Submission #1434419
Source Code Expand
#include <bits/stdc++.h> using namespace std; struct Trie{ int v; int nx[27]; } tr[800010]; int n, qn, cnt, p[27], cs[100010][27][27]; char buf[400010]; vector<char> v[100010]; queue<int> q; stack<int> st; void go(int &t, int c){ if(!tr[t].nx[c]) tr[t].nx[c] = ++cnt; t = tr[t].nx[c]; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++){ scanf("%s", buf); int t = 0; for(int j = 0; buf[j]; j++){ v[i].push_back(buf[j]); int c = buf[j] - 'a' + 1; go(t, c); } go(t, 0); tr[t].v++; } q.push(0); while(!q.empty()){ int cur = q.front(); q.pop(); st.push(cur); for(int i = 0; i < 27; i++){ if(tr[cur].nx[i]) q.push(tr[cur].nx[i]); } } while(!st.empty()){ int cur = st.top(); st.pop(); for(int i = 0; i < 27; i++){ if(tr[cur].nx[i]) tr[cur].v += tr[tr[cur].nx[i]].v; } } for(int i = 1; i <= n; i++){ int t = 0; for(int j = 0; j < v[i].size(); j++){ int c = v[i][j] - 'a' + 1; for(int k = 0; k <= 26; k++) if(tr[t].nx[k]) cs[i][c][k] += tr[tr[t].nx[k]].v; go(t, c); } } scanf("%d", &qn); for(int k; qn--; ){ scanf("%d%s", &k, buf + 1); for(int i = 1; i <= 26; i++) p[i] = buf[i] - 'a' + 1; int ret = 0; for(int i = 1; i <= 26; i++){ for(int j = 0; p[j] != i; j++){ ret += cs[k][i][p[j]]; } } printf("%d\n", ret + 1); } }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | kdh9949 |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 1385 Byte |
Status | AC |
Exec Time | 235 ms |
Memory | 318208 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:21:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:23:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%s", buf); ^ ./Main.cpp:55:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &qn); ^ ./Main.cpp:57:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%s", &k, buf + 1); ^
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 | 232 ms | 316032 KB |
02.txt | AC | 230 ms | 316032 KB |
03.txt | AC | 231 ms | 316032 KB |
04.txt | AC | 232 ms | 316032 KB |
05.txt | AC | 214 ms | 159104 KB |
06.txt | AC | 175 ms | 62336 KB |
07.txt | AC | 170 ms | 54016 KB |
08.txt | AC | 166 ms | 51712 KB |
09.txt | AC | 163 ms | 51712 KB |
10.txt | AC | 149 ms | 51584 KB |
11.txt | AC | 151 ms | 100224 KB |
12.txt | AC | 167 ms | 143872 KB |
13.txt | AC | 184 ms | 189568 KB |
14.txt | AC | 168 ms | 60160 KB |
15.txt | AC | 158 ms | 51968 KB |
16.txt | AC | 143 ms | 51584 KB |
17.txt | AC | 148 ms | 51580 KB |
18.txt | AC | 109 ms | 9344 KB |
19.txt | AC | 108 ms | 9344 KB |
20.txt | AC | 110 ms | 9344 KB |
21.txt | AC | 110 ms | 9344 KB |
22.txt | AC | 110 ms | 9344 KB |
23.txt | AC | 166 ms | 129408 KB |
24.txt | AC | 150 ms | 98176 KB |
25.txt | AC | 167 ms | 141824 KB |
26.txt | AC | 104 ms | 9344 KB |
27.txt | AC | 117 ms | 21888 KB |
28.txt | AC | 118 ms | 28288 KB |
29.txt | AC | 114 ms | 15744 KB |
30.txt | AC | 146 ms | 71680 KB |
31.txt | AC | 123 ms | 24320 KB |
32.txt | AC | 115 ms | 15744 KB |
33.txt | AC | 119 ms | 21888 KB |
34.txt | AC | 118 ms | 19840 KB |
35.txt | AC | 122 ms | 24192 KB |
36.txt | AC | 235 ms | 318208 KB |
37.txt | AC | 130 ms | 30332 KB |
38.txt | AC | 128 ms | 30332 KB |
39.txt | AC | 3 ms | 6400 KB |
40.txt | AC | 3 ms | 6400 KB |
s1.txt | AC | 3 ms | 6400 KB |
s2.txt | AC | 3 ms | 6400 KB |