FOJ 题目 2075 Substring (后缀数组求出现k次的最小字典序子串)

Problem 2075 Substring

Accept: 70    Submit: 236
Time Limit: 1000 mSec    Memory Limit : 65536 KB

Problem Description

Given a string, find a substring of it which the original string contains exactly n such substrings.

Input

There are several cases. The first line of each case contains an integer n.The second line contains a string, no longer than 100000.

Output

If the such substring doesn't exist, output "impossible", else output the substring that appeared n times in the original string.If there are multiple solutions, output lexicographic smallest substring.

Sample Input

2ababba

Sample Output

ac代码
#include           
#include           
#include           
#include          
#define min(a,b) (a>b?b:a)       
#define max(a,b) (a>b?a:b)        
using namespace std;          
char str[103030];        
int sa[103030],Rank[103030],rank2[103030],height[103030],c[103030],*x,*y;      
int n;      
void cmp(int n,int sz)      
{      
    int i;      
    memset(c,0,sizeof(c));      
    for(i=0;i=0;i--)      
        sa[--c[x[y[i]]]]=y[i];      
}      
void build_sa(char *s,int n,int sz)      
{      
    x=Rank,y=rank2;      
    int i,j;      
    for(i=0;i=len)      
                y[yid++]=sa[i]-len;      
            cmp(n,sz);      
        swap(x,y);      
        x[sa[0]]=yid=0;      
        for(i=1;i=n)      
            break;      
    }      
    for(i=0;i>1]+1;    
    }    
}    
void init_RMQ(int n)    
{    
    int i,j,k;    
    for(i=1;i<=n;i++)    
    {    
        minv[i][0]=height[i];    
    }    
    for(j=1;j<=lg[n];j++)      
    {      
        for(k=0;k+(1<r)    
        swap(l,r);    
    l++;    
    int k=lg[r-l+1];    
    return min(minv[l][k],minv[r-(1<n)
			break;
		int t=lcp(sa[i],sa[i+k-1]);
		if(t>height[i]&&(i+k>n||t+k<=n&&t>height[i+k]))
		{
			for(j=0;j


 
    

 
    


Source

FOJ有奖月赛-2012年3月

你可能感兴趣的:(后缀数组)