# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1040959 | 2024-08-01T12:49:33 Z | ArthuroWich | Type Printer (IOI08_printer) | C++17 | 809 ms | 93900 KB |
#include <bits/stdc++.h> using namespace std; int trie[20*25005][26], le[20*25005][26], co = 1, en[20*25005]; vector<char> ans; void insert(string s) { int n = 0; for (int i = 0; i < s.length(); i++) { char c = s[i]; le[n][c-'a'] = max(le[n][c-'a'], (int)s.length()-i); if (!trie[n][c-'a']) { trie[n][c-'a'] = co; co++; } n = trie[n][c-'a']; } en[n] = 1; } void dfs(int a) { if (en[a]) { ans.push_back('P'); } vector<pair<int, int>> v; for (int i = 0; i < 26; i++) { if (trie[a][i]) { v.push_back({le[a][i], i}); } } sort(v.begin(), v.end()); for (auto [_, i] : v) { ans.push_back((char)(i+'a')); dfs(trie[a][i]); ans.push_back('-'); } } void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; insert(s); } dfs(0); while(!ans.empty() && ans.back() == '-') { ans.pop_back(); } cout << ans.size() << endl; for (char c : ans) { cout << c << endl; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t; t = 1; while(t--) { solve(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 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 | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 7 ms | 1252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 1928 KB | Output is correct |
2 | Correct | 17 ms | 2324 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 5724 KB | Output is correct |
2 | Correct | 99 ms | 11852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 13948 KB | Output is correct |
2 | Correct | 40 ms | 3256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 306 ms | 34752 KB | Output is correct |
2 | Correct | 723 ms | 79056 KB | Output is correct |
3 | Correct | 353 ms | 40944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 244 ms | 26968 KB | Output is correct |
2 | Correct | 809 ms | 93900 KB | Output is correct |
3 | Correct | 447 ms | 46560 KB | Output is correct |
4 | Correct | 743 ms | 89288 KB | Output is correct |