1031: [JSOI2007] character encryption cipher
Time Limit:10 Sec Memory limit:162 MB
submit:4175 solved:1694
[Submit] [Status] [Discuss]
Description
Like to delve into the problem of JS classmate, and recently fascinated by the encryption method of thinking. One day, he suddenly came up with what he thought was the ultimate encryption: to make a circle of information that needs to be encrypted, it is clear that they have a very different way of reading. To be read as a proportion of:
JSOI07 soi07j oi07js i07jso 07JSOI 7jsoi0 sort them according to the size of the string: 07JSOI 7jsoi0 i07jso JSOI07 oi07js soi07j read the last column of characters: I0O7SJ, the word after the encryption String (in fact, this encryption is very easy to crack, because it is suddenly thought out.) That's ^ ^ ^). But. Suppose the string you want to encrypt is too long, can you write a program to complete this task?
Input
The input file includes one row. The string that you want to encrypt. Note that the contents of a string are not necessarily letters, numbers, or symbols.
Output
The output line. is the encrypted string.
Sample Input
JSOI07
Sample Output
I0o7sj
HINT
The length of the data string for 100% does not exceed 100000.
Idea: a template title for the suffix array.
We just need to copy this string to the back, and then handle the SA, which in turn outputs the starting point in the ranking.
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;#define N n*2-1Const intm=200100;CharCH[M];intn,m=0, Sa[m],t1[m],t2[m],c[m];voidBuild_sa () {intI,p,k,*x=t1,*y=t2; for(i=0; i<m;++i) c[i]=0; for(i=0; i<n;++i) c[x[i]=ch[i]]++; for(i=1; i<m;++i) c[i]+=c[i-1]; for(i=n-1; i>=0; i.) sa[--c[x[i]]]=i; for(k=1; k<=n;k<<=1) {p=0; for(i=n-k;i<n;++i) y[p++]=i; for(i=0; i<n;++i)if(sa[i]>=k) Y[p++]=sa[i]-k; for(i=0; i<m;++i) c[i]=0; for(i=0; i<n;++i) c[x[y[i]]]++; for(i=0; i<m;++i) c[i]+=c[i-1]; for(i=n-1; i>=0;----) sa[--c[x[y[i]]]]=y[i]; Swap (x, y); p=1; x[sa[0]]=0; for(i=1; i<n;++i) x[sa[i]]=y[sa[i-1]]==y[sa[i]]&&y[sa[i-1]+k]==y[sa[i]+k]?p-1:p + +;if(p>=n) Break; M=p; }}intMain () {intI,j;scanf('%s ', &ch); n=strlen(CH); for(i=0; i<n-1; ++i) Ch[i+n]=ch[i]; for(i=0; i<n;++i) M=max (M, (int) ch[i]); m+=1; Build_sa (); for(i=0; i<n;++i)if(sa[i]<n)printf("%c", ch[sa[i]+n-1]);}
[bzoj1031] [JSOI2007] Character encryption cipher