Test instructions: It's better to understand.
Analysis: Invert each word, build a dictionary tree, and then violently match the encrypted string
Note: Then I just don't understand, the above kind can, and the time is very short, but I think vice versa.
The first I wrote was to reverse the cipher string, and then the word was built into the dictionary tree, and then it was tle, and it could have been written backwards.
Really baffled, and then I guess the number of words is probably less
#include <cstdio>#include<iostream>#include<cstring>#include<cstdlib>#include<vector>#include<string>#include<algorithm>using namespaceStd;typedefLong LongLL;Const intn=1000000+5;Chars[10005];Charstr[100005][1005];intlen[100005];inttrie[n][ -],mk[n];intans[10005],tot,cnt,m,n;voidAddintx) { intnow=0; for(inti=len[x]-1; i>=0; --i) {Chartmp=Str[x][i]; if(tmp<'a'|| Tmp>'Z') TMP+='a'-'A'; intp=tmp-'a'; if(!trie[now][p]) trie[now][p]=++CNT; now=Trie[now][p]; } Mk[now]=x;}voidSolveintPOS) { if(pos==N) { for(intI=1; i<tot; ++i) printf ("%s", Str[ans[i]]); printf ("%s\n", Str[ans[tot]]); Exit (0); } intnow=0; for(inti=pos+1; i<=n; ++i) {intp=s[i]-'a'; now=Trie[now][p]; if(!now) Break; if(Mk[now]) {ans[++tot]=Mk[now]; Solve (POS+Len[mk[now]]); --tot; } }}intMain () {scanf ("%d%s", &n,s+1);//for (int i=1; i<=n/2; ++i)//swap (s[i],s[n-i+1]);scanf"%d",&m); for(intI=1; i<=m; ++i) {scanf ("%s", Str[i]); Len[i]=strlen (Str[i]); Add (i); } Solve (0); return 0;}
View Code
Codeforces 633 C Spy syndrome 2 Dictionary tree