# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
916949 | 2024-01-26T20:14:21 Z | SonicML | Type Printer (IOI08_printer) | C++14 | 104 ms | 49936 KB |
#include <iostream> #include <fstream> using namespace std; int n, gSize; int const NMAX = 5e5; int g[1 + NMAX]['z' - 'a' + 1]; int finish[1 + NMAX]; int printed = 0; string big = ""; string ans = ""; void DFS(int node, int depth) { for(int i = 1;i <= finish[node];i++) { ans.push_back('P'); printed++; } for(char c = 'a';c <= 'z';c++) { int to = g[node][c - 'a']; if(to && (depth >= big.size() || c != big[depth])) { ans.push_back(c); DFS(to, depth+1); if(printed < n) { ans.push_back('-'); } } } if(depth < big.size() && g[node][big[depth] - 'a']) { int to = g[node][big[depth] - 'a']; ans.push_back(big[depth]); DFS(to, depth+1); if(printed < n) { ans.push_back('-'); } } } int main() { cin >> n; string s; for(int i = 1;i <= n;i++) { cin >> s; int node = 0; for(int pos = 0;pos < s.size();pos++) { if(g[node][s[pos] - 'a'] == 0) { gSize++; g[node][s[pos] - 'a'] = gSize; } node = g[node][s[pos] - 'a']; } if(big.size() < s.size()) { big = s; } finish[node]++; } //cerr << big << '\n'; DFS(0, 0); cout << ans.size() << '\n'; for(int i = 0;i < ans.size();i++) { cout << ans[i] << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 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 | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 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 | 1 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 | 6 ms | 3164 KB | Output is correct |
2 | Correct | 12 ms | 6488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 7660 KB | Output is correct |
2 | Correct | 9 ms | 1884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 48 ms | 18416 KB | Output is correct |
2 | Correct | 104 ms | 42000 KB | Output is correct |
3 | Correct | 58 ms | 22004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 14328 KB | Output is correct |
2 | Correct | 102 ms | 49936 KB | Output is correct |
3 | Correct | 65 ms | 24772 KB | Output is correct |
4 | Correct | 84 ms | 47120 KB | Output is correct |