# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197460 | 2020-01-21T11:42:30 Z | SamAnd | Type Printer (IOI08_printer) | C++17 | 166 ms | 50028 KB |
#include <bits/stdc++.h> using namespace std; const int N = 25003, M = 22; int n; int maxu; char u[M]; int z; int t[N * M][26]; int q[N * M]; bool c[N * M]; vector<char> ans; void dfs(int x) { for (int i = 0; i < q[x]; ++i) ans.push_back('P'); for (int i = 0; i < 26; ++i) { if (t[x][i]) { if (!c[t[x][i]]) { ans.push_back(i + 'a'); dfs(t[x][i]); } } } for (int i = 0; i < 26; ++i) { if (t[x][i]) { if (c[t[x][i]]) { ans.push_back(i + 'a'); dfs(t[x][i]); } } } if (!c[x]) ans.push_back('-'); } int main() { scanf("%d", &n); while (n--) { char a[M]; scanf(" %s", a); int m = strlen(a); int pos = 0; for (int i = 0; i < m; ++i) { if (!t[pos][a[i] - 'a']) t[pos][a[i] - 'a'] = ++z; pos = t[pos][a[i] - 'a']; } ++q[pos]; if (m > maxu) { maxu = m; for (int i = 0; i < m; ++i) u[i] = a[i]; } } int pos = 0; c[pos] = true; for (int i = 0; i < maxu; ++i) { if (!t[pos][u[i] - 'a']) t[pos][u[i] - 'a'] = ++z; pos = t[pos][u[i] - 'a']; c[pos] = true; } dfs(0); printf("%d\n", ans.size()); for (int i = 0; i < ans.size(); ++i) printf("%c\n", ans[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 380 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1144 KB | Output is correct |
2 | Correct | 5 ms | 1272 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 3192 KB | Output is correct |
2 | Correct | 22 ms | 6520 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 7716 KB | Output is correct |
2 | Correct | 12 ms | 2040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 65 ms | 18540 KB | Output is correct |
2 | Correct | 140 ms | 42092 KB | Output is correct |
3 | Correct | 75 ms | 22000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 60 ms | 14672 KB | Output is correct |
2 | Correct | 166 ms | 50028 KB | Output is correct |
3 | Correct | 86 ms | 24908 KB | Output is correct |
4 | Correct | 144 ms | 47296 KB | Output is correct |