# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659637 | 2022-11-18T20:33:13 Z | pakapu | Type Printer (IOI08_printer) | C++17 | 138 ms | 100972 KB |
#include <bits/stdc++.h> using namespace std; struct node { node* c[26]; bool end = false; bool marked = false; node() { for(int i = 0; i < 26; i++) { c[i] = nullptr; } } }; vector<char> result; struct trie { node* head; trie() { head = new node; //head -> marked = true; } void add(string s, bool m) { node* curr = head; for(int i = 0; i < s.size(); i++) { if(curr -> c[s[i] - 'a'] == nullptr) { curr -> c[s[i] - 'a'] = new node; } curr -> marked = m; curr = curr -> c[s[i] - 'a']; } curr -> marked = m; curr -> end = true; } void out() { out(head, nullptr); } void out(node* v, node* prev) { if(v -> end) { result.push_back('P'); } int mi = -1; for(int i = 0; i < 26; i++) { if(v -> c[i] != nullptr) { if(v -> c[i] -> marked) { mi = i; continue; } result.push_back((char)(i + 'a')); out(v -> c[i], v); } } if(mi != -1) { result.push_back((char)(mi + 'a')); out(v -> c[mi], v); } if(!v -> marked) { result.push_back('-'); } } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<string> a(n); string mx = ""; for(int i = 0; i < n; i++) { cin >> a[i]; if(a[i].size() > mx.size()) { mx = a[i]; } } trie t; for(auto c : a) { t.add(c, false); } t.add(mx, true); t.out(); cout << result.size() << '\n'; for(auto c : result) { 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 | 0 ms | 340 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 | 1 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 | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 1 ms | 1108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1748 KB | Output is correct |
2 | Correct | 4 ms | 2260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 6028 KB | Output is correct |
2 | Correct | 15 ms | 12740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 14920 KB | Output is correct |
2 | Correct | 8 ms | 3796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 37248 KB | Output is correct |
2 | Correct | 113 ms | 84864 KB | Output is correct |
3 | Correct | 53 ms | 44496 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 29256 KB | Output is correct |
2 | Correct | 138 ms | 100972 KB | Output is correct |
3 | Correct | 66 ms | 50504 KB | Output is correct |
4 | Correct | 102 ms | 95520 KB | Output is correct |