# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
889085 | 2023-12-18T19:19:20 Z | Macker | Type Printer (IOI08_printer) | C++17 | 127 ms | 60824 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define all(v) v.begin(), v.end() struct node{ node* par; map<char, node*> m = {}; int d = 0; int mxd = 0; bool vis = 0; node* mxch = NULL; bool end = 0; }; void add(string s, int i, node* cur){ if(i == s.size()){ cur->end = true; return; } if(cur->m.find(s[i]) == cur->m.end()){ cur->m[s[i]] = new node({cur}); } add(s, i + 1, cur->m[s[i]]); } int depthDfs(node* a){ if(a->m.size() == 1){ a->mxch = (*a->m.begin()).second; a->d = depthDfs((*a->m.begin()).second) + 1; } else{ a->d = 0; for (auto &b : a->m) { int nd = depthDfs(b.second) + 1; if(nd > a->mxd){ a->mxd = nd; a->mxch = b.second; } } } return max(a->d, a->mxd - 1); } vector<char> res; void resDfs(node* a, bool first){ char c; if(a->end) res.push_back('P'); for (auto &b : a->m) { if(b.second == a->mxch && first){ c = b.first; continue; } res.push_back(b.first); resDfs(b.second, false); res.push_back('-'); } if(first && a->mxch){ res.push_back(c); resDfs(a->mxch, true); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; node* root = new node({NULL}); for (int i = 0; i < n; i++) { string s; cin >> s; add(s, 0, root); } depthDfs(root); resDfs(root, true); cout << res.size() << endl; for (auto &i : res) cout << i <<"\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 456 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 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 | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 860 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1372 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 4440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 10972 KB | Output is correct |
2 | Correct | 14 ms | 2648 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 26576 KB | Output is correct |
2 | Correct | 127 ms | 60824 KB | Output is correct |
3 | Correct | 74 ms | 31432 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 45 ms | 20940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |