# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
396179 | 2021-04-29T14:09:47 Z | Berted | Type Printer (IOI08_printer) | C++14 | 148 ms | 51684 KB |
#include <iostream> using namespace std; const int INF = 1e8; int N; string ans; int adj[500001][26], cnt[500001], DP[500001], sz = 0; inline int newNode() { for (int i = 0; i < 26; i++) adj[sz][i] = -1; return sz++; } inline void insert(int u, int i, const string& s) { if (i < s.size()) { int &v = adj[u][s[i] - 'a']; if (v == -1) {v = newNode();} insert(v, i + 1, s); DP[u] = max(DP[u], DP[v] + 1); } else {cnt[u]++;} } inline void solve(int u, bool m) { int hvy = -1; for (int i = 0; i < cnt[u]; i++) ans.push_back('P'); for (int i = 0; i < 26; i++) { if (adj[u][i] != -1 && m && (hvy == -1 || DP[adj[u][i]] > DP[adj[u][hvy]])) hvy = i; } for (int i = 0; i < 26; i++) { if (adj[u][i] != -1 && hvy != i) { ans.push_back(i + 'a'); solve(adj[u][i], 0); ans.push_back('-'); } } if (hvy != -1) {ans.push_back(hvy + 'a'); solve(adj[u][hvy], 1);} } int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N; newNode(); for (int i = 0; i < N; i++) {string S; cin >> S; insert(0, 0, S);} solve(0, 1); cout << ans.size() << "\n"; for (const char &c : ans) cout << c << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 332 KB | Output is correct |
2 | Correct | 2 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1100 KB | Output is correct |
2 | Correct | 4 ms | 1356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3284 KB | Output is correct |
2 | Correct | 19 ms | 6732 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 7772 KB | Output is correct |
2 | Correct | 9 ms | 1996 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 56 ms | 18864 KB | Output is correct |
2 | Correct | 134 ms | 43128 KB | Output is correct |
3 | Correct | 67 ms | 22212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 14872 KB | Output is correct |
2 | Correct | 148 ms | 51684 KB | Output is correct |
3 | Correct | 75 ms | 25696 KB | Output is correct |
4 | Correct | 131 ms | 48660 KB | Output is correct |