# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880667 | 2023-11-29T19:59:03 Z | OAleksa | Type Printer (IOI08_printer) | C++14 | 43 ms | 41068 KB |
#include<bits/stdc++.h> using namespace std; #define int long long #define f first #define s second vector<char> ans; const int maxn = 5e5 + 69; int trie[maxn][26], kraj[maxn], ban[maxn]; int n, node; void add(string s) { int m = s.size(); int t = 0; for (int i = 0;i < m;i++) { int x = s[i] - 'a'; if (trie[t][x] == 0) trie[t][x] = ++node; t = trie[t][x]; } kraj[t]++; } void dfs(int v) { for (int i = 0;i < kraj[v];i++) ans.push_back('P'); int x = -1; for (int i = 0;i < 26;i++) { if (trie[v][i] && ban[trie[v][i]] != 1) { ans.push_back((char)(i + 'a')); dfs(trie[v][i]); ans.push_back('-'); } else if (ban[trie[v][i]] == 1) x = i; } if (x != -1) { ans.push_back((char)(x + 'a')); dfs(trie[v][x]); ans.push_back('-'); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt = 1; //cin >> tt; while (tt--) { cin >> n; vector<string> a(n); for (int i = 0;i < n;i++) { cin >> a[i]; add(a[i]); } sort(a.begin(), a.end()); int t = 0; for (int i = 0;i < a.back().size();i++) { int x = a[n - 1][i] - 'a'; t = trie[t][x]; ban[t] = 1; } dfs(0); while (ans.back() == '-') ans.pop_back(); cout << ans.size() << '\n'; for (auto x : ans) cout << x << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2392 KB | Output is correct |
2 | Correct | 0 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2556 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 2396 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 3932 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 7772 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 20192 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 43 ms | 41068 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 37 ms | 33500 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |