# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746977 | 2023-05-23T10:11:46 Z | khulegub | Type Printer (IOI08_printer) | C++14 | 75 ms | 53188 KB |
#include <bits/stdc++.h> using namespace std; const int N = 500005; /** Node count*/ int k = 1; int to[N][26]; char a[N]; int h[N]; bool last[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 (last[u]) { 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]; } // Mark the end of the word. last[curr] = true; } 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 | 20 ms | 51140 KB | Output is correct |
2 | Correct | 20 ms | 51156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 51156 KB | Output is correct |
2 | Correct | 21 ms | 51116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 51176 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 51104 KB | Output is correct |
2 | Incorrect | 19 ms | 51152 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 51128 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 51212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 28 ms | 51540 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 41 ms | 52000 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 75 ms | 53188 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 67 ms | 52840 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |