# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721321 | thimote75 | Type Printer (IOI08_printer) | C++14 | 1082 ms | 57896 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;
vector<char> chr_buffer;
struct Trie {
map<char, Trie*> m;
int count = 0;
int mxSize = 0;
void append (string &buffer, int offset) {
if (offset == buffer.size()) { count ++; return ; }
mxSize = max(mxSize, (int) buffer.size());
if (m.find(buffer[offset]) == m.end())
m.insert({ buffer[offset], new Trie() });
Trie* tr = (*m.find(buffer[offset])).second;
tr->append(buffer, offset + 1);
}
void show () {
for (int i = 0; i < count; i ++)
chr_buffer.push_back('P');
bool found = false;
for (auto u : m) {
if (u.second->mxSize == mxSize && !found) {
found = true;
continue ;
}
chr_buffer.push_back(u.first);
u.second->show();
chr_buffer.push_back('-');
}
for (auto u : m) {
if (u.second->mxSize != mxSize) continue ;
chr_buffer.push_back(u.first);
u.second->show();
chr_buffer.push_back('-');
break;
}
}
};
Trie res;
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
string b;
for (int i = 0; i < N; i ++) {
cin >> b;
res.append(b, 0);
}
res.show();
while (chr_buffer[chr_buffer.size() - 1] == '-')
chr_buffer.pop_back();
cout << chr_buffer.size() << endl;
for (char c : chr_buffer)
cout << c << endl;
}
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... |