Submission #921136
Source Code Expand
#include <iostream> #include <fstream> #include <set> #include <map> #include <string> #include <vector> #include <bitset> #include <algorithm> #include <cstring> #include <cstdlib> #include <cmath> #include <cassert> #include <queue> #define mp make_pair #define pb push_back typedef long long ll; typedef long double ld; using namespace std; const int MAXN = 120000; const int MX = 450000; int go[MX][26]; int cc[MX]; int fl[MX]; int nowcc = 1; int gg[26][26]; int gg2; int aa2[MAXN]; int aa[MAXN][26][26]; int n,q; int newn() { fl[nowcc] = -1; return nowcc++; } void add(const string &s, int i) { int now = 0; for (int i = 0; i < (int)s.size(); ++i) { ++cc[now]; if (go[now][s[i] - 'a']) now = go[now][s[i] - 'a']; else now = go[now][s[i] - 'a'] = newn(); } ++cc[now]; fl[now] = i; } void dfs1(int v) { if (fl[v] != -1) { memcpy(aa[fl[v]], gg, sizeof(gg)); aa2[fl[v]] = gg2; } if (fl[v] != -1) ++gg2; for (int i = 0; i < 26; ++i) { if (go[v][i]) { for (int j = 0; j < 26; ++j) if (go[v][j] && j != i) { gg[i][j] += cc[go[v][j]]; } dfs1(go[v][i]); for (int j = 0; j < 26; ++j) if (go[v][j] && j != i) { gg[i][j] -= cc[go[v][j]]; } } } if (fl[v] != -1) --gg2; } void build() { dfs1(0); } char buf[MX]; string s[MAXN]; int main() { scanf("%d", &n); fl[0] = -1; for (int i = 0; i < n; ++i) { scanf(" %s", buf); s[i] = buf; add(s[i], i); } build(); scanf("%d", &q); for (int i = 0; i < q; ++i) { int k; scanf("%d%s", &k, buf); --k; int ans = 1 + aa2[k]; for (int j = 0; j < 26; ++j) for (int l = j + 1; l < 26; ++l) ans += aa[k][buf[l] - 'a'][buf[j] - 'a']; printf("%d\n", ans); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | LHiC |
Language | C++14 (GCC 5.4.1) |
Score | 1100 |
Code Size | 1821 Byte |
Status | AC |
Exec Time | 498 ms |
Memory | 280960 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:87:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:90:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf(" %s", buf); ^ ./Main.cpp:95:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &q); ^ ./Main.cpp:98:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%s", &k, buf); ^
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 | 495 ms | 280960 KB |
02.txt | AC | 498 ms | 280960 KB |
03.txt | AC | 495 ms | 280960 KB |
04.txt | AC | 498 ms | 280960 KB |
05.txt | AC | 366 ms | 141696 KB |
06.txt | AC | 246 ms | 55680 KB |
07.txt | AC | 226 ms | 48256 KB |
08.txt | AC | 225 ms | 46336 KB |
09.txt | AC | 214 ms | 46208 KB |
10.txt | AC | 218 ms | 50304 KB |
11.txt | AC | 236 ms | 85888 KB |
12.txt | AC | 284 ms | 124032 KB |
13.txt | AC | 343 ms | 167296 KB |
14.txt | AC | 235 ms | 53632 KB |
15.txt | AC | 214 ms | 46208 KB |
16.txt | AC | 216 ms | 50304 KB |
17.txt | AC | 235 ms | 64640 KB |
18.txt | AC | 96 ms | 4480 KB |
19.txt | AC | 95 ms | 4480 KB |
20.txt | AC | 96 ms | 4480 KB |
21.txt | AC | 96 ms | 4480 KB |
22.txt | AC | 96 ms | 4480 KB |
23.txt | AC | 280 ms | 113536 KB |
24.txt | AC | 233 ms | 84736 KB |
25.txt | AC | 282 ms | 122752 KB |
26.txt | AC | 95 ms | 4480 KB |
27.txt | AC | 124 ms | 16768 KB |
28.txt | AC | 133 ms | 22912 KB |
29.txt | AC | 113 ms | 9344 KB |
30.txt | AC | 209 ms | 59904 KB |
31.txt | AC | 139 ms | 18560 KB |
32.txt | AC | 115 ms | 11520 KB |
33.txt | AC | 133 ms | 19584 KB |
34.txt | AC | 125 ms | 16512 KB |
35.txt | AC | 139 ms | 20224 KB |
36.txt | AC | 490 ms | 279552 KB |
37.txt | AC | 162 ms | 33280 KB |
38.txt | AC | 162 ms | 33280 KB |
39.txt | AC | 4 ms | 1280 KB |
40.txt | AC | 4 ms | 1152 KB |
s1.txt | AC | 4 ms | 1152 KB |
s2.txt | AC | 4 ms | 1280 KB |