Submission #522471

# Submission time Handle Problem Language Result Execution time Memory
522471 2022-02-05T04:54:06 Z Jesus Type Printer (IOI08_printer) C++14
90 / 100
1000 ms 36108 KB
#include <bits/stdc++.h>
 
using namespace std;
 
vector<char> ans;
 
struct arbol{
    char letra;
    int palabra_mayor;
    bool fin_palabra=false;
    vector<int> hijos;
};
 
int aux,desocupado=1;
 
arbol raices[500002];
 
int dfs(int posicion){
    int tam=0;
    for(int i:raices[posicion].hijos){
        tam=max(dfs(i),tam);
    }
    tam++;
    raices[posicion].palabra_mayor=tam;
    return tam;
}
 
void res(int pos, bool rama){
    if(pos!=0) {
            ans.push_back(raices[pos].letra);
    }
    if(raices[pos].fin_palabra==true) {
            ans.push_back('P');
    }
    int m=-1;
    for(int i:raices[pos].hijos){
            if(raices[i].palabra_mayor==raices[pos].palabra_mayor-1&&m==-1) m=i;
            else res(i,false);
    }
    if(pos==0&&m!=-1) res(m,true);
    else if(m!=-1) res(m,rama);
    if(pos!=0&&rama==false) {
            ans.push_back('-');
    }
}
 
 
int main()
{
    int n;
    cin>>n;
    string palabra;
    bool c=false;
    for(int i=0;i<n;i++){
        cin>>palabra;
        aux=0;
        for(char l:palabra){
            c=false;
            for(int j:raices[aux].hijos){
                if(raices[j].letra==l) {
                        c=true;
                        aux=j;
                        break;
                }
            }
            if(c==false){
                raices[aux].hijos.push_back(desocupado);
                aux=desocupado;
                raices[aux].letra=l;
                desocupado++;
            }
        }
        raices[aux].fin_palabra=true;
    }
    dfs(0);
    res(0,false);
    cout<<ans.size()<<endl;
    for(char r:ans){
        cout<<r<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19844 KB Output is correct
2 Correct 9 ms 19788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19828 KB Output is correct
2 Correct 10 ms 19788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 19788 KB Output is correct
2 Correct 9 ms 19860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19748 KB Output is correct
2 Correct 9 ms 19792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 19864 KB Output is correct
2 Correct 19 ms 19996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 20128 KB Output is correct
2 Correct 30 ms 20172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 20676 KB Output is correct
2 Correct 153 ms 21820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 22144 KB Output is correct
2 Correct 61 ms 20484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 25484 KB Output is correct
2 Correct 895 ms 33544 KB Output is correct
3 Correct 485 ms 26908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 24068 KB Output is correct
2 Execution timed out 1060 ms 36108 KB Time limit exceeded
3 Halted 0 ms 0 KB -