# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000136 | 2024-06-16T17:26:51 Z | amin_2008 | Type Printer (IOI08_printer) | C++17 | 904 ms | 121384 KB |
#include "bits/stdc++.h" using namespace std; #define int long long const int sz = 5e5 + 5; const int inf = 1e18; int trie[sz][26]; int depth[sz]; bool leaf[sz]; int nxt = 0, cnt = 0; char ch[sz]; vector<int> adj[sz]; vector<char> res; int n; struct Trie { void add(string s) { int root = 0; for(int i = 0; i < s.size(); i++) { int child = s[i] - 'a'; if (!trie[root][child]) { trie[root][child] = ++nxt; adj[root].push_back(trie[root][child]); ch[trie[root][child]] = s[i]; } root = trie[root][child]; depth[root] = max(depth[root], (int)s.size() - i); } leaf[root] = true; } void dfs(int node) { if (node) res.push_back(ch[node]); if (leaf[node]) res.push_back('P'), cnt++; for(int to : adj[node]) dfs(to); if (cnt != n) res.push_back('-'); } }; void solve() { cin >> n; Trie tree; for(int i = 1; i <= n; i++) { string s; cin >> s; tree.add(s); } for(int i = 0; i <= nxt; i++) sort(adj[i].begin(), adj[i].end(), [&](int a, int b) { return depth[a] < depth[b]; }); tree.dfs(0); cout << res.size() << endl; for(char c : res) cout << c << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12124 KB | Output is correct |
2 | Correct | 4 ms | 12124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12124 KB | Output is correct |
2 | Correct | 3 ms | 12124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12124 KB | Output is correct |
2 | Correct | 3 ms | 12124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12120 KB | Output is correct |
2 | Correct | 4 ms | 12120 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 12124 KB | Output is correct |
2 | Correct | 11 ms | 13132 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 13888 KB | Output is correct |
2 | Correct | 21 ms | 14168 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 55 ms | 18372 KB | Output is correct |
2 | Correct | 115 ms | 25472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 140 ms | 27864 KB | Output is correct |
2 | Correct | 42 ms | 15448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 354 ms | 51916 KB | Output is correct |
2 | Correct | 785 ms | 103884 KB | Output is correct |
3 | Correct | 402 ms | 58832 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 319 ms | 43060 KB | Output is correct |
2 | Correct | 904 ms | 121384 KB | Output is correct |
3 | Correct | 469 ms | 65224 KB | Output is correct |
4 | Correct | 849 ms | 115276 KB | Output is correct |