# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74680 | 2018-09-06T12:08:24 Z | PeppaPig | Type Printer (IOI08_printer) | C++14 | 87 ms | 21412 KB |
#include <bits/stdc++.h> using namespace std; const int N = 5e5+5; int n, ptr, cnt, line; int t[N][30], sub[N]; char print[N*4]; int subSize(int u) { sub[u] = 1; for(int i = 0; i < 26; i++) if(t[u][i]) sub[u] += subSize(t[u][i]); return sub[u]; } void dfs(int u) { int mx = 0, hv = -1; for(int i = 0; i < 26; i++) if(t[u][i] && sub[t[u][i]] > mx) mx = sub[t[u][i]], hv = i; if(hv == -1) print[line++] = 'P', cnt++; else { for(int i = 0; i < 26; i++) if(t[u][i] && i != hv) print[line++] = 'a'+i, dfs(t[u][i]); print[line++] = 'a'+hv; dfs(t[u][hv]); } if(cnt < n) print[line++] = '-'; } 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++) { if(!t[cptr][A[i]-'a']) t[cptr][A[i]-'a'] = ++ptr; cptr = t[cptr][A[i]-'a']; } } subSize(0); dfs(0); printf("%d\n", line); for(int i = 0; i < line; i++) printf("%c\n", print[i]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 460 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 460 KB | Output is correct |
2 | Correct | 2 ms | 580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 2 ms | 580 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 580 KB | Output is correct |
2 | OK | 2 ms | 580 KB | Checker has crashed |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 2 ms | 708 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 5 ms | 1492 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 12 ms | 3852 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 31 ms | 8796 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 87 ms | 21412 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | OK | 64 ms | 21412 KB | Checker has crashed |
2 | Halted | 0 ms | 0 KB | - |