# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746975 | 2023-05-23T10:05:45 Z | khulegub | Type Printer (IOI08_printer) | C++14 | 24 ms | 21412 KB |
#include <bits/stdc++.h> using namespace std; const int N = 100000; /** Node count*/ int k = 1; int to[N][26]; char a[N]; int h[N]; vector<char> ans; void calc_height(int u) { int height = 0; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { int v = to[u][i]; calc_height(v); height = max(height, 1 + h[v]); } } h[u] = height; } void dfs(int u) { if (u > 0) ans.push_back(a[u]); vector<pair<int, int> > children; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { int v = to[u][i]; children.push_back({h[v], v}); } } sort(children.begin(), children.end()); for (int i = 0; i < children.size(); i++) { int v = children[i].second; dfs(v); } if (h[u] == 0) { ans.push_back('P'); } if (u > 0) ans.push_back('-'); } int main() { int n; cin >> n; memset(to, -1, sizeof to); for (int i = 0; i < n; i++) { string s; cin >> s; int curr = 0; for (int j = 0; j < s.length(); j++) { int c = s[j] - 'a'; if (to[curr][c] == -1) { // Create a new node. to[curr][c] = k; k++; } a[to[curr][c]] = s[j]; curr = to[curr][c]; } } calc_height(0); dfs(0); while (ans.size() > 0 && ans.back() == '-') ans.pop_back(); cout << ans.size() << '\n'; for (char c : ans) cout << c << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 10452 KB | Output is correct |
2 | Correct | 5 ms | 10452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 10452 KB | Output is correct |
2 | Correct | 4 ms | 10452 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 10376 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 10452 KB | Output is correct |
2 | Incorrect | 5 ms | 10452 KB | didn't print every word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 10452 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 10580 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 10836 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 11336 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 19 ms | 21412 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 20 ms | 21372 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |