Submission #1434368
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]; 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; } } 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 t = 0, ret = 0; for(int i = 0; i < v[k].size(); i++){ int c = v[k][i] - 'a' + 1; for(int j = 0; p[j] != c; j++) if(tr[t].nx[p[j]]) ret += tr[tr[t].nx[p[j]]].v; go(t, c); } printf("%d\n", ret + 1); } }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | kdh9949 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1215 Byte |
Status | TLE |
Exec Time | 6307 ms |
Memory | 50048 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:47:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &qn); ^ ./Main.cpp:49: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 | 0 / 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 | 110 ms | 31360 KB |
02.txt | AC | 109 ms | 31360 KB |
03.txt | AC | 111 ms | 31360 KB |
04.txt | AC | 108 ms | 31360 KB |
05.txt | AC | 162 ms | 44416 KB |
06.txt | AC | 404 ms | 50048 KB |
07.txt | AC | 1216 ms | 49920 KB |
08.txt | AC | 5566 ms | 49664 KB |
09.txt | TLE | 6304 ms | 49536 KB |
10.txt | TLE | 6304 ms | 49408 KB |
11.txt | AC | 102 ms | 12160 KB |
12.txt | AC | 102 ms | 16896 KB |
13.txt | AC | 103 ms | 19584 KB |
14.txt | AC | 387 ms | 47872 KB |
15.txt | TLE | 6304 ms | 49792 KB |
16.txt | TLE | 6304 ms | 49408 KB |
17.txt | TLE | 6304 ms | 49404 KB |
18.txt | AC | 1222 ms | 5248 KB |
19.txt | AC | 1225 ms | 5248 KB |
20.txt | AC | 1430 ms | 5248 KB |
21.txt | AC | 1433 ms | 5248 KB |
22.txt | AC | 1436 ms | 5248 KB |
23.txt | AC | 106 ms | 16768 KB |
24.txt | AC | 106 ms | 12160 KB |
25.txt | AC | 104 ms | 16896 KB |
26.txt | AC | 1043 ms | 5248 KB |
27.txt | AC | 324 ms | 9600 KB |
28.txt | AC | 261 ms | 11904 KB |
29.txt | AC | 2010 ms | 11648 KB |
30.txt | AC | 140 ms | 16384 KB |
31.txt | AC | 949 ms | 18176 KB |
32.txt | TLE | 6303 ms | 13568 KB |
33.txt | TLE | 6307 ms | 19712 KB |
34.txt | TLE | 6304 ms | 17664 KB |
35.txt | TLE | 6304 ms | 21888 KB |
36.txt | AC | 113 ms | 31488 KB |
37.txt | TLE | 6304 ms | 28028 KB |
38.txt | TLE | 6304 ms | 28028 KB |
39.txt | AC | 3 ms | 4352 KB |
40.txt | AC | 3 ms | 4352 KB |
s1.txt | AC | 3 ms | 4352 KB |
s2.txt | AC | 3 ms | 4352 KB |