# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
550914 | 2022-04-19T11:36:30 Z | Jomnoi | Type Printer (IOI08_printer) | C++17 | 195 ms | 147632 KB |
#include <bits/stdc++.h> #define DEBUG false using namespace std; vector <char> ans; class Node { public : bool finish; int len[26]; Node *c[26]; Node() : finish(false) { for(int i = 0; i < 26; i++) { c[i] = NULL; len[i] = 0; } } }; void add(Node *node, string s, int idx = 0) { if(idx == s.length()) { node->finish = true; return; } int v = s[idx] - 'a'; if(node->c[v] == NULL) { node->c[v] = new Node(); } node->len[v] = max(node->len[v], (int)s.length()); add(node->c[v], s, idx + 1); } void solve(Node *node) { if(node->finish == true) { ans.push_back('P'); } vector <pair <int, int>> vec; for(int v = 0; v < 26; v++) { if(node->c[v] != NULL) { vec.emplace_back(node->len[v], v); } } sort(vec.begin(), vec.end()); for(auto [l, v] : vec) { ans.push_back(char(v + 'a')); solve(node->c[v]); ans.push_back('-'); } } int main() { cin.tie(nullptr)->sync_with_stdio(false); int N; cin >> N; Node *root = new Node(); for(int i = 1; i <= N; i++) { string s; cin >> s; add(root, s); } solve(root); while(ans.back() == '-') { ans.pop_back(); } cout << ans.size() << '\n'; for(auto c : ans) { cout << c << '\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 0 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 468 KB | Output is correct |
2 | Correct | 3 ms | 1492 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 2516 KB | Output is correct |
2 | Correct | 4 ms | 3156 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 8636 KB | Output is correct |
2 | Correct | 28 ms | 18388 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 21656 KB | Output is correct |
2 | Correct | 11 ms | 4820 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 53968 KB | Output is correct |
2 | Correct | 152 ms | 123976 KB | Output is correct |
3 | Correct | 86 ms | 63792 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 42048 KB | Output is correct |
2 | Correct | 195 ms | 147632 KB | Output is correct |
3 | Correct | 122 ms | 72440 KB | Output is correct |
4 | Correct | 172 ms | 139428 KB | Output is correct |