An interesting question
In the test room, hash the code into an integer, multiply the value of the last asicc Code * 1 by * 10, get an integer, and then rank nlogn in disorder using the equality and uniqueness.
The proof is as follows:
For plaintext ABCDE
Ciphertext bcdef
There are (a-B) * 10000 + (B-c) * 1000 + (c-d) * 100 + (D-f) * 10 + (e-f) * 1 = a constant
We can pre-process this constant. For any f [a, B], A, and B belong to lowercase letters, we can pre-process the value.
Okay, this is the test room.
Sort and maintain the labels in sequence after preprocessing, and then pass O (n) over again. It's silly.
Ch round #57-story of the OI class
However, I finally thought about it again, but I still can directly hash it. After hash is used, it will be dedback ..
Const maxn = 600001; maxm = 26; maxlen = 5; var N, T, I, J: longint; A, B: array [0 .. maxn] of longint; F: array [0 .. maxm, 0 .. maxm] of longint; s: string; begin readln (n); for I: = 1 to maxm do for J: = 1 to maxm do if j> = I then f [I, j]: = J-I else f [I, j]: = 26-i + J; // obtain the value of hash for I: = 1 to n do begin readln (s); T: = 0; for J: = 1 to maxlen-1 do t: = T * 26 + F [ord (s [J])-ord ('A') + 1] [ord (s [J + 1]) -ord ('A') + 1]; A [T]: = I; B [T]: = ord (s [1]); // maintain the end label; for I: = 1 to n do begin readln (s); T: = 0; for J: = 1 to maxlen-1 do t: = T * 26 + F [ord (s [J])-ord ('A') + 1] [ord (s [J + 1]) -ord ('A') + 1]; writeln (A [T], '', F [ord (s [1])-ord ('A ') + 1] [ord (B [T])-ord ('A') + 1]); end.
Ch round #57-story of the OI class Caesar Password