# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1000128 | 2024-06-16T17:15:03 Z | vjudge1 | Type Printer (IOI08_printer) | C++17 | 919 ms | 155344 KB |
#include "bits/stdc++.h" using namespace std; #define int long long const int sz = 18e5 + 5; const int inf = 1e18; int trie[sz][26]; int depth[sz]; int 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 | 14 ms | 42584 KB | Output is correct |
2 | Correct | 16 ms | 42584 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 42588 KB | Output is correct |
2 | Correct | 15 ms | 42724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 42588 KB | Output is correct |
2 | Correct | 15 ms | 42756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 42584 KB | Output is correct |
2 | Correct | 15 ms | 42588 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 16 ms | 42844 KB | Output is correct |
2 | Correct | 22 ms | 43504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 44376 KB | Output is correct |
2 | Correct | 34 ms | 44892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 67 ms | 49088 KB | Output is correct |
2 | Correct | 136 ms | 56408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 152 ms | 59084 KB | Output is correct |
2 | Correct | 62 ms | 46196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 362 ms | 83660 KB | Output is correct |
2 | Correct | 804 ms | 137416 KB | Output is correct |
3 | Correct | 418 ms | 91044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 294 ms | 74440 KB | Output is correct |
2 | Correct | 919 ms | 155344 KB | Output is correct |
3 | Correct | 476 ms | 97736 KB | Output is correct |
4 | Correct | 903 ms | 149240 KB | Output is correct |