# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
573022 | a_aguilo | Type Printer (IOI08_printer) | C++14 | 53 ms | 13692 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 nodo{
char letra;
int max_prof;
vector<nodo*> listaAdy;
nodo(char c){
letra = c;
max_prof = 0;
}
};
struct nodo_smaller{
bool operator()(nodo* const &n1, nodo* const &n2) const {
return n1->max_prof < n2->max_prof;
}
};
//sort(V.begin(),V.end(), nodo_smaller{});
int construir(int pos, string& S, nodo* prev){
if(pos == S.size()) return 0;
nodo* act = NULL;
for(nodo* vecino: prev->listaAdy){
if(vecino->letra == S[pos]) act = vecino;
}
if(act == NULL){
act = new nodo(S[pos]);
prev->listaAdy.push_back(act);
}
act->max_prof = max(act->max_prof, 1 +construir(pos+1, S, act));
return act->max_prof;
}
string type_printer (nodo* act, bool last){
string ans = "";
if(act->letra != '.') ans.push_back(act->letra);
if (act->listaAdy.size()== 0){
ans.push_back('P');
}
else{
sort(act->listaAdy.begin(), act->listaAdy.end(), nodo_smaller{});
for(int i = 0; i < act->listaAdy.size()-1; ++i){
ans = ans + type_printer(act->listaAdy[i], false);
}
ans = ans + type_printer(act->listaAdy[act->listaAdy.size()-1], last);
}
if(!last and (act->letra !='.')) ans.push_back('-');
return ans;
}
int main(){
int n;
string S;
cin >> n;
nodo inicio = nodo('.');
for(int i = 0; i < n; ++i){
cin >> S;
construir(0, S, &inicio);
}
string res = type_printer(&inicio, true);
cout << res.size() << '\n';
for(char c: res) cout << c << '\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... |