[bzoj1031] [JSOI2007] Character encryption cipher

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.