# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
533998 | nemethm | Type Printer (IOI08_printer) | C++17 | 191 ms | 51492 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 <vector>
#include <cmath>
#include <algorithm>
#include <deque>
#include <map>
#include <queue>
using namespace std;
using ll = long long int;
deque<char> sol;
struct trie
{
map<char, trie> tr;
int size = 0, ending = 0, maxl = 0;
void insert(const string& str, int hol){
++size;
if(hol == str.size()){
++ending;
return;
}
tr[str[hol]].insert(str, hol + 1);
maxl = max(maxl, tr[str[hol]].maxl + 1);
}
void erase(const string& str, int hol){
--size;
if(hol == str.size()){
--ending;
return;
}
tr[str[hol]].erase(str, hol + 1);
}
int index(const string& str, int hol){
return 0;
}
void solve(){
if(ending > 0){
sol.push_back('P');
}
priority_queue<pair<int,char>> q;
for(auto& i : tr){
q.push({-i.second.maxl, i.first});
}
while(!q.empty()){
char c = q.top().second; q.pop();
sol.push_back(c);
tr[c].solve();
sol.push_back('-');
}
}
};
int main()
{
trie t;
int n;
cin >> n;
while(n--){
string s;
cin >> s;
t.insert(s, 0);
}
t.solve();
while(sol.back() == '-') sol.pop_back();
cout << sol.size() << endl;
for(auto i : sol){
cout << 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... |