Submission #1161986
Source Code Expand
#pragma optimization_level 3 #include <cstdio> #include <iostream> #include <algorithm> #include <string> #include <vector> #include <queue> #include <set> #include <map> #include <cmath> using namespace std; typedef pair<int, int> P; #define rep(i, n) for (int i=0; i<(n); i++) #define all(c) (c).begin(), (c).end() #define _1 first #define _2 second #define pb push_back #define INF 1145141919 #define MOD 1000000007 int N, Q; string S[100000]; int C[100000]; int R[100000][26][26]; int p[256]; class Trie { public: Trie *a[26]; int ctr; bool leaf; Trie() { for (int i=0; i<26; i++) a[i] = NULL; leaf = false; ctr = 0; } void insert(const char *s) { if (*s == '\0') { leaf = true; ctr++; return; } int k = *s - 'a'; if (a[k] == NULL) { a[k] = new Trie(); } a[k]->insert(s+1); ctr++; } int find(const char *s, int x) { if (*s == '\0') return leaf; int c = leaf; int k = *s - 'a'; for (int i=0; i<26; i++) { if (a[i] != NULL) { R[x][i][k] += a[i]->ctr; } } if (a[k] == NULL) return c; c += a[k]->find(s+1, x); return c; } }; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; rep(i, N) cin >> S[i]; cin >> Q; Trie trie; rep(i, N) trie.insert(S[i].c_str()); rep(i, N) { C[i] = trie.find(S[i].c_str(), i); } rep(i, Q) { int k; cin >> k; k--; rep(i, 26) { char c; cin >> c; p[c - 'a'] = i; } int s = C[k]; rep(i, 26) { rep(j, 26) { if (p[i] < p[j]) s += R[k][i][j]; } } cout << s << "\n"; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Lexicographical disorder |
User | funcsr |
Language | C++14 (Clang 3.8.0) |
Score | 1100 |
Code Size | 1751 Byte |
Status | AC |
Exec Time | 752 ms |
Memory | 293504 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 | 752 ms | 290168 KB |
02.txt | AC | 743 ms | 289536 KB |
03.txt | AC | 744 ms | 289536 KB |
04.txt | AC | 745 ms | 289536 KB |
05.txt | AC | 712 ms | 173824 KB |
06.txt | AC | 659 ms | 101632 KB |
07.txt | AC | 652 ms | 94720 KB |
08.txt | AC | 645 ms | 92800 KB |
09.txt | AC | 636 ms | 92928 KB |
10.txt | AC | 635 ms | 95616 KB |
11.txt | AC | 641 ms | 91392 KB |
12.txt | AC | 655 ms | 129152 KB |
13.txt | AC | 676 ms | 173440 KB |
14.txt | AC | 660 ms | 97536 KB |
15.txt | AC | 636 ms | 92672 KB |
16.txt | AC | 635 ms | 95488 KB |
17.txt | AC | 639 ms | 104952 KB |
18.txt | AC | 602 ms | 7552 KB |
19.txt | AC | 603 ms | 7552 KB |
20.txt | AC | 602 ms | 7808 KB |
21.txt | AC | 603 ms | 7808 KB |
22.txt | AC | 604 ms | 7808 KB |
23.txt | AC | 665 ms | 121728 KB |
24.txt | AC | 639 ms | 89472 KB |
25.txt | AC | 653 ms | 129280 KB |
26.txt | AC | 597 ms | 7552 KB |
27.txt | AC | 615 ms | 24320 KB |
28.txt | AC | 618 ms | 31744 KB |
29.txt | AC | 610 ms | 19200 KB |
30.txt | AC | 642 ms | 71552 KB |
31.txt | AC | 623 ms | 34048 KB |
32.txt | AC | 606 ms | 23296 KB |
33.txt | AC | 609 ms | 37120 KB |
34.txt | AC | 607 ms | 32256 KB |
35.txt | AC | 610 ms | 40576 KB |
36.txt | AC | 752 ms | 293504 KB |
37.txt | AC | 625 ms | 54908 KB |
38.txt | AC | 624 ms | 54908 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 |