# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544567 | DragosC1 | Type Printer (IOI08_printer) | C++17 | 162 ms | 58380 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 <iostream>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;
struct trie {
bool cuv;
int down;
map<int, trie*> lit;
trie() {
cuv = down = 0;
}
};
trie *root;
string s;
void add(trie *node, int ind) {
if (ind == s.size()) {
node->cuv = 1;
return;
}
int l = s[ind] - 'a';
if (node->lit[l] == NULL)
node->lit[l] = new trie();
add(node->lit[l], ind + 1);
node->down = max(node->down, node->lit[l]->down + 1);
}
string rez;
void dfs(trie *node) {
if (node->cuv == 1)
rez.push_back('P');
vector<pair<int, char>> v;
for (auto it = node->lit.begin(); it != node->lit.end(); it++)
v.push_back({node->lit[it->first]->down, it->first});
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
rez.push_back(v[i].second + 'a');
dfs(node->lit[v[i].second]);
rez.push_back('-');
}
}
int main() {
root = new trie();
int i, n;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> s;
add(root, 0);
}
dfs(root);
while (rez.back() == '-')
rez.pop_back();
cout << rez.size() << '\n';
for (i = 0; i < rez.size(); i++)
cout << rez[i] << '\n';
return 0;
}
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... |