# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1012432 | 2024-07-02T07:13:56 Z | vjudge1 | Type Printer (IOI08_printer) | C++17 | 81 ms | 57304 KB |
#include <bits/stdc++.h> #define ll long long #define pii pair <int, int> using namespace std; const int N = 1e6 + 10; const int siz = 28; struct node { int ch[siz]; int vis; int biggest; } trie[N]; int ncnt, rt; char s[N][22]; vector <char> ans; inline void insert(char *s, int ok) { int p = rt; for (int i = 0; s[i]; ++i) { int j = s[i] - 'a'; if (!trie[p].ch[j]) trie[p].ch[j] = ++ncnt; trie[p].biggest |= ok; p = trie[p].ch[j]; } trie[p].biggest |= ok; trie[p].vis ++; } inline int find(char *s) { int p = rt; for (int i = 0; s[i]; ++i) { int j = s[i] - 'a'; if (!trie[p].vis) return 0; p = trie[p].ch[j]; } return trie[p].vis; } inline void dfs(int x) { if (trie[x].vis) { ans.push_back('P'); } for (int i = 0; i < siz; ++i) { if (trie[x].ch[i] && !trie[trie[x].ch[i]].biggest) { ans.push_back(i + 'a'); dfs(trie[x].ch[i]); } } for (int i = 0; i < siz; ++i) { if (trie[x].ch[i] && trie[trie[x].ch[i]].biggest) { ans.push_back(i + 'a'); dfs(trie[x].ch[i]); } } if (x) ans.push_back('-'); } int main() { int n; scanf("%d", &n); int maxn = 0, id = 0; for (int i = 1; i <= n; ++i) { scanf("%s", s[i]); if(strlen(s[i]) > maxn) { maxn = strlen(s[i]); id = i; } } for (int i = 1; i <= n; ++i) { if (i == id) insert(s[i], 1); else insert(s[i], 0); } dfs(0); int k = ans.size() - 1; while (ans[k] == '-' && k > 0) k --; k += 1; printf("%d\n", k); for (int i = 0; i < k; ++i) printf("%c\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 604 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1116 KB | Output is correct |
2 | Correct | 3 ms | 1372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 3932 KB | Output is correct |
2 | Correct | 10 ms | 7260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 10676 KB | Output is correct |
2 | Correct | 6 ms | 4444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 22736 KB | Output is correct |
2 | Correct | 68 ms | 48580 KB | Output is correct |
3 | Correct | 46 ms | 26416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 18332 KB | Output is correct |
2 | Correct | 81 ms | 57304 KB | Output is correct |
3 | Correct | 44 ms | 29460 KB | Output is correct |
4 | Correct | 76 ms | 54216 KB | Output is correct |