1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:3146 solved:1226
[Submit] [Status] 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 many different ways of reading. For example, it can be read as: JSOI07 soi07j oi07js i07jso 07JSOI 7jsoi0 sort them by the size of the string: 07JSOI 7jsoi0 i07jso JSOI07 oi07js soi07j read the last column of characters: I0o7 SJ, is the encrypted string (in fact, this encryption method is very easy to crack, because it is suddenly thought out, then ^ ^). However, if the string you want to encrypt is too long, can you write a program to accomplish this task?
Input
The input file contains a row of strings 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 InputJSOI07
Sample OutputI0O7SJ
Data size
The length of the data string for 40% does not exceed 10000.
The length of the data string for 100% does not exceed 100000.
HINT Source
Exercises
I didn't know how to water before.
Copy the original string to the back, do the suffix array, and then sweep it all over again to
Not at the end + auxiliary character cause last night no A
Code:
1#include <cstdio>2#include <cstdlib>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <iostream>7#include <vector>8#include <map>9#include <Set>Ten#include <queue> One#include <string> A #defineINF 1000000000 - #defineMAXN 250000+10000 - #defineMAXM 500+100 the #defineEPS 1e-10 - #definell Long Long - #definePA pair<int,int> - using namespacestd; + stringS,ss; - intN,A[MAXN],SA[MAXN],WA[MAXN],WB[MAXN],WR[MAXN],WV[MAXN]; +InlineBOOLcmpint*r,intAintBintl) A { at returnr[a]==r[b]&&r[a+l]==r[b+l]; - } - voidDaint*r,int*sa,intNintm) - { - inti,j,p,*x=wa,*y=wb,*T; - for(i=0; i<m;i++) wr[i]=0; in for(i=0; i<n;i++) wr[x[i]=r[i]]++; - for(i=1; i<m;i++) wr[i]+=wr[i-1]; to for(i=n-1; i>=0; i--) sa[--wr[x[i]]]=i; + for(j=1, p=1;p <n;j<<=1, m=p) - { the for(p=0, i=n-j;i<n;i++) y[p++]=i; * for(i=0; i<n;i++)if(SA[I]>=J) y[p++]=sa[i]-J; $ for(i=0; i<m;i++) wr[i]=0;Panax Notoginseng for(i=0; i<n;i++) wr[x[y[i]]]++; - for(i=1; i<m;i++) wr[i]+=wr[i-1]; the for(i=n-1; i>=0; i--) sa[--wr[x[y[i]]]]=Y[i]; + for(t=x,x=y,y=t,p=1, x[sa[0]]=0, i=1; i<n;i++) AX[SA[I]]=CMP (y,sa[i-1],sa[i],j)? p1:p + +; the } + } - intMain () $ { $Freopen ("Input.txt","R", stdin); -Freopen ("output.txt","W", stdout); -cin>>s;n=s.length (); the for(intI=0; i<n;i++) a[i]=int(S[i]); - for(intI=0; i<n;i++) a[n+i]=int(S[i]);Wuyia[2*n]=0; theDa (A,sa,2*n+1,129); -ss=""; Wu for(intI=0; i<=2*n;i++) - if(sa[i]<n) ss=ss+s[(sa[i]-1+n)%n]; Aboutcout<<ss<<Endl; $ return 0; -}
View Code
BZOJ1031: [JSOI2007] character encryption cipher