1031: [JSOI2007] character encryption cipher time limit:10 Sec Memory limit:162 MB
submit:7593 solved:3291
[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 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: I0O7SJ, 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 InputJSOI07Sample OutputI0O7SJHINT
The length of the data string for 100% does not exceed 100000.
Source
Analysis: Two strings stored with a suffix array, then as long as the dictionary-ordered output answer is good.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #include <sstream> #include <list> #include <assert.h> #include < bitset> #include <numeric> #define DEBUG () puts ("++++") #define GCD (A, B) __gcd (A, b) #define Lson l,m,rt<<1 #define Rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr (x) ((x) * (x)) #define MS (a , b) memset (A, B, sizeof a) #define SZ size () #define PU push_up#define PD push_down#define CL Clear () #define ALL 1,n,1#defin E for (i,x,n) for (int i = (x); I < (n); ++i) #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("Out . txt "," w ", stdout) using namespace Std;typedef long Long LL; typedef unsigned long Long ull;typedef pair<int, int> p;const int INF = 0x3f3f3f3f;const LL LNF = 1e17;const Double inf = 1e20;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int maxn = 2e5 + 10;const int maxm = 3e5 + 10;const ULL mod = 3;const int dr[] = {-1, 0, 1, 0};const int dc[] = {0,-1, 0, 1};const char *de[] = {"0000", "0001", "0010", "00 One "," 0100 "," 0101 "," 0110 "," 0111 "," $ "," 1001 "," 1010 "," 1011 "," 1100 "," 1101 "," 1110 "," 1111 "};int N, m;const int mo N[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 3, +, 0, +, +, +, +, +, + 0, 31};inline bool is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} struct array{int S[MAXN], SA[MAXN], T[MAXN], T2[MAXN]; int H[MAXN], R[MAXN], C[MAXN]; int n; void Init () {n = 0; memset (SA, 0, sizeof SA); } void Build_sa (int m) {int *x = t, *y = t2; for (int i = 0; i < m; ++i) c[i] = 0; for (int i = 0; i < n; ++i) ++c[x[i] = s[i]]; for (int i = 1; i < m; ++i) c[i] + = c[i-1]; for (int i = n-1; I >= 0; i.) sa[--c[x[i]] [i]; for (int k = 1; k <= N; k <<= 1) {int p = 0; for (int i = n-k; i < n; ++i) y[p++] = i; for (int i = 0; i < n; ++i) if (Sa[i] >= k) y[p++] = sa[i]-K; for (int i = 0; i < m; ++i) c[i] = 0; for (int i = 0; i < n; ++i) ++c[x[y[i]]; for (int i = 1; i < m; ++i) c[i] + = c[i-1]; for (int i = n-1; I >= 0; i) sa[--c[x[y[i]]] [= Y[i]; Swap (x, y); p = 1; X[sa[0]] = 0; for (int 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; }} void Gethight () {int k = 0; for (int i = 0; i < n; ++i) r[sa[i]] = i; for (int i = 0; i < n; ++i) {if (k)--k; Int j = Sa[r[i]-1]; while (s[i+k] = = S[j+k]) ++k; H[r[i]] = k; }}};char S[MAXN]; Array Arr;int Main () {SCANF ("%s", s); Arr.init (); for (int i = 0; s[i]; ++i, ++n) arr.s[arr.n++] = s[i]; for (int i = 0; s[i]; ++i) arr.s[arr.n++] = s[i]; arr.s[arr.n++] = 0; Arr.build_sa (130); Arr.gethight (); for (int i = 1; I <= n*2; ++i) if (Arr.sa[i] < n) printf ("%c", arr.s[arr.sa[i]+n-1]); printf ("\ n"); return 0;}
Bzoj 1031 [JSOI2007] character encryption cipher (suffix array)