# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74683 | 2018-09-06T12:49:08 Z | PeppaPig | Type Printer (IOI08_printer) | C++14 | 169 ms | 52468 KB |
#include <bits/stdc++.h> #define pii pair<int, int> #define x first #define y second using namespace std; const int N = 5e5+5; int n, ptr, cnt; int t[N][30], sub[N], w[N], h[N], c[N]; bitset<N> leaf; vector<char> C; int subSize(int u) { sub[u] = 1; for(int i = 0; i < 26; i++) { int v = t[u][i]; if(!v) continue; sub[u] += subSize(v); if(sub[v] > w[u]) { w[u] = sub[v]; h[u] = v; c[u] = i; } } return sub[u]; } void dfs(int u) { if(leaf[u]) C.emplace_back('P'); for(int i = 0; i < 26; i++) { int v = t[u][i]; if(!v || v == h[u]) continue; C.emplace_back('a'+i); dfs(v); } if(h[u]) { C.emplace_back('a'+c[u]); dfs(h[u]); } C.emplace_back('-'); } int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { char A[25]; scanf(" %s", A+1); int cptr = 0; for(int i = 1; i <= strlen(A+1); i++) { int &pos = t[cptr][A[i]-'a']; if(!pos) pos = ++ptr; cptr = pos; } leaf[cptr] = 1; } subSize(0); /*for(int i = 0; i <= ptr; i++) printf("%c ", 'a'+hv[i].y); printf("\n"); for(int i = 0; i <= ptr; i++) { for(int j = 0; j < 26; j++) { if(t[i][j]) printf("%c ", 'a'+j); else printf("- "); } printf("\n"); }*/ dfs(0); while(!C.empty() && C.back() == '-') C.pop_back(); printf("%d\n", C.size()); for(char c : C) printf("%c\n", c); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 508 KB | Output is correct |
2 | Correct | 2 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 508 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 508 KB | Output is correct |
2 | Correct | 2 ms | 508 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 692 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 1488 KB | Output is correct |
2 | Incorrect | 7 ms | 1872 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 4104 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 33 ms | 9512 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 23028 KB | Output is correct |
2 | Correct | 169 ms | 52468 KB | Output is correct |
3 | Incorrect | 92 ms | 52468 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 66 ms | 52468 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |