Submission #921306
Source Code Expand
#include <bits/stdc++.h> #define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++) #define REP(i,b) FOR(i,0,b) #define ALL(c) c.begin(),c.end() #define PB push_back #define cat //cout << __LINE__ << endl; using namespace std; typedef long long LL; typedef double ld; typedef int ut; typedef complex<int> cli; typedef vector<ut> VI; typedef pair<ut,ut> pr; typedef pair<ut,pr> ppr; typedef vector<pr> Vpr; typedef vector<ppr> Vppr; typedef priority_queue<pr,Vpr> PQ; const int SIZE=5+1e5; const int alpha='z'-'a'+1; int nums[SIZE][alpha][alpha]; int smaller[SIZE]; string s[SIZE]; struct Trie{ Trie* next[alpha]; bool isEnd; int size,tall; void init(){ size=0; isEnd=false; } Trie():tall(0){init();} Trie(int x):tall(x){init();} Trie* nextNode(int target,bool unmake=false); Trie* nextNode(string &s,bool unmake=false){ if(s.size()==tall) return NULL; return nextNode(s[tall]-'a',unmake); } }; Trie root; Trie nodes[SIZE*10]; int nextnodes=1; Trie* Trie::nextNode(int target,bool unmake){ if(!next[target]){ if(unmake) return &nodes[0]; next[target] = &nodes[nextnodes++]; next[target]->tall=tall+1; } return next[target]; } bool find(string &s,Trie* now){ while(now->nextNode(s)){ now=now->nextNode(s); } return now->isEnd; } void add(string &s,Trie* root){ Trie* now=root; while(now->nextNode(s)){ now->size++; now=now->nextNode(s); } now->isEnd=true; now->size++; } void analys(int x){ Trie* now= &root; REP(i,s[x].size()){ if(now->isEnd) smaller[x]++; FOR(j,'a','z'+1){ if(s[x][i]==j) continue; nums[x][j-'a'][s[x][i]-'a']+=now->nextNode(j-'a',true)->size; } now=now->nextNode(s[x],true); } } bool isFaster(string &p,char a,char b){ REP(i,p.size()){ if(p[i]==a) return true; if(p[i]==b) return false; } } int solve(int x,string p){ int ans=0; REP(i,alpha) REP(j,i){ ans+=nums[x][p[j]-'a'][p[i]-'a']; //if(nums[x][i][j])cout << x <<" " << char(i+'a') <<" " << char(j+'a') << " " << nums[x][i][j] << endl; } return ans+smaller[x]; } int main(){ int N; cin.tie(0); cin >> N; REP(i,SIZE*10) nodes[i].init(); REP(i,N){ cin >> s[i]; add(s[i], &root); } REP(i,N){ analys(i); } int Q,k; cin >> Q; string p; REP(i,Q){ cin >> k >> p; cout << solve(k-1,p)+1 << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | reew2n |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 2383 Byte |
Status | AC |
Exec Time | 1505 ms |
Memory | 489472 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 | 1490 ms | 489472 KB |
02.txt | AC | 1505 ms | 489472 KB |
03.txt | AC | 1500 ms | 489472 KB |
04.txt | AC | 1498 ms | 489472 KB |
05.txt | AC | 1293 ms | 328448 KB |
06.txt | AC | 1054 ms | 231552 KB |
07.txt | AC | 996 ms | 223360 KB |
08.txt | AC | 982 ms | 221056 KB |
09.txt | AC | 954 ms | 220800 KB |
10.txt | AC | 959 ms | 220544 KB |
11.txt | AC | 1247 ms | 301696 KB |
12.txt | AC | 1272 ms | 338432 KB |
13.txt | AC | 1334 ms | 379520 KB |
14.txt | AC | 1052 ms | 231552 KB |
15.txt | AC | 964 ms | 220928 KB |
16.txt | AC | 959 ms | 220544 KB |
17.txt | AC | 967 ms | 220548 KB |
18.txt | AC | 969 ms | 223104 KB |
19.txt | AC | 964 ms | 223104 KB |
20.txt | AC | 970 ms | 223104 KB |
21.txt | AC | 975 ms | 223104 KB |
22.txt | AC | 981 ms | 223104 KB |
23.txt | AC | 1289 ms | 325632 KB |
24.txt | AC | 1219 ms | 300416 KB |
25.txt | AC | 1287 ms | 337024 KB |
26.txt | AC | 968 ms | 223104 KB |
27.txt | AC | 1042 ms | 231296 KB |
28.txt | AC | 1060 ms | 235648 KB |
29.txt | AC | 961 ms | 222080 KB |
30.txt | AC | 1183 ms | 269184 KB |
31.txt | AC | 983 ms | 224000 KB |
32.txt | AC | 979 ms | 220928 KB |
33.txt | AC | 951 ms | 220544 KB |
34.txt | AC | 960 ms | 220544 KB |
35.txt | AC | 962 ms | 220672 KB |
36.txt | AC | 1492 ms | 489088 KB |
37.txt | AC | 962 ms | 220552 KB |
38.txt | AC | 959 ms | 220552 KB |
39.txt | AC | 257 ms | 219776 KB |
40.txt | AC | 255 ms | 219776 KB |
s1.txt | AC | 256 ms | 219776 KB |
s2.txt | AC | 256 ms | 219776 KB |