Submission #921101
Source Code Expand
#include<iostream> #include<map> using namespace std; const int NQmax = 100000; int N,Q; string S[NQmax]; int prefix[NQmax]; map<int, int> former[NQmax]; struct trie { int k; // index of this node int n; // number of children struct trie* c[26]; } root[400000]; int main(){ cin >> N; for(int i=0; i<N; i++){ cin >> S[i]; } int n = 1; for(int i=0; i<N; i++){ struct trie *t = root; for(int j=0; j<S[i].size(); j++){ int c = S[i][j]-'a'; if(t->c[c] == NULL) t->c[c] = root+n; n++; t->c[c]->n++; t=t->c[c]; } t->k=i+1; } for(int i=0; i<N; i++){ struct trie *t=root; for(int j=0; j<S[i].size(); j++){ int c = S[i][j]-'a'; struct trie* s = t->c[c]; if(t->k > 0) prefix[i]++; for(int k=0; k<26; k++){ if(k==c|| t->c[k]==NULL) continue; former[i][k*26+c] += t->c[k]->n; } t=s; } } cin >> Q; for(int i=0; i<Q; i++){ int K; string P; cin >> K; cin >> P; int res = prefix[K-1]+1; for(char j=0; j<26; j++){ for(int k=j+1; k<26; k++){ int l=(P[j]-'a')*26+P[k]-'a'; auto m=former[K-1].find(l); if(m != former[K-1].end()) res += m->second; } } cout << res << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | emak |
Language | C++14 (Clang 3.8.0) |
Score | 1100 |
Code Size | 1362 Byte |
Status | AC |
Exec Time | 3074 ms |
Memory | 447744 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1100 / 1100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 3057 ms | 439296 KB |
02.txt | AC | 3015 ms | 439552 KB |
03.txt | AC | 3019 ms | 439296 KB |
04.txt | AC | 3020 ms | 439424 KB |
05.txt | AC | 2347 ms | 224512 KB |
06.txt | AC | 1693 ms | 100736 KB |
07.txt | AC | 1544 ms | 92544 KB |
08.txt | AC | 1438 ms | 90496 KB |
09.txt | AC | 1274 ms | 90112 KB |
10.txt | AC | 1039 ms | 90112 KB |
11.txt | AC | 980 ms | 63232 KB |
12.txt | AC | 1086 ms | 90496 KB |
13.txt | AC | 1263 ms | 128512 KB |
14.txt | AC | 1031 ms | 91648 KB |
15.txt | AC | 950 ms | 90112 KB |
16.txt | AC | 965 ms | 90112 KB |
17.txt | AC | 937 ms | 90104 KB |
18.txt | AC | 836 ms | 6144 KB |
19.txt | AC | 836 ms | 6144 KB |
20.txt | AC | 2350 ms | 21760 KB |
21.txt | AC | 2339 ms | 21760 KB |
22.txt | AC | 2369 ms | 21504 KB |
23.txt | AC | 1078 ms | 98176 KB |
24.txt | AC | 983 ms | 63872 KB |
25.txt | AC | 1072 ms | 91392 KB |
26.txt | AC | 844 ms | 9472 KB |
27.txt | AC | 972 ms | 22912 KB |
28.txt | AC | 1034 ms | 32384 KB |
29.txt | AC | 927 ms | 18432 KB |
30.txt | AC | 1351 ms | 88704 KB |
31.txt | AC | 1261 ms | 36608 KB |
32.txt | AC | 925 ms | 23168 KB |
33.txt | AC | 945 ms | 35200 KB |
34.txt | AC | 948 ms | 31104 KB |
35.txt | AC | 1018 ms | 39552 KB |
36.txt | AC | 3074 ms | 447744 KB |
37.txt | AC | 939 ms | 47868 KB |
38.txt | AC | 937 ms | 47868 KB |
39.txt | AC | 9 ms | 4992 KB |
40.txt | AC | 8 ms | 4992 KB |
s1.txt | AC | 8 ms | 4992 KB |
s2.txt | AC | 9 ms | 4992 KB |