# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
739885 | Desh03 | Type Printer (IOI08_printer) | C++17 | 58 ms | 36576 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
struct node {
node* c[26] = {NULL};
bool endofword;
node(bool x) : endofword(x) { };
};
vector<char> ans;
struct trie {
node* root;
trie() : root(new node(false)) { };
void insert(node* &u, int id, string &s) {
if (u == NULL) u = new node(false);
if (id == s.size()) {
u->endofword = true;
return;
}
insert(u->c[s[id] - 'a'], id + 1, s);
}
void dfs(node* u) {
if (u->endofword) ans.push_back('P');
for (int i = 0; i < 26; i++)
if (u->c[i] != NULL) {
ans.push_back('a' + i);
dfs(u->c[i]);
}
ans.push_back('-');
}
void insert(string s) {
insert(root, 0, s);
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
trie tr;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
tr.insert(s);
}
tr.dfs(tr.root);
while (ans.back() == '-') ans.pop_back();
cout << ans.size() << '\n';
for (char c : ans) cout << c << '\n';
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |