Submission #522460

# Submission time Handle Problem Language Result Execution time Memory
522460 2022-02-05T04:30:44 Z Jesus Type Printer (IOI08_printer) C++17
0 / 100
53 ms 49348 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;
}

int 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;
}

Compilation message

printer.cpp: In function 'int res(int, bool)':
printer.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
   45 | }
      | ^
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 40200 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 40156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 40156 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 40208 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 40160 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 40524 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 29 ms 41552 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 43756 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 53 ms 49348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 46816 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -