Submission #1093857

# Submission time Handle Problem Language Result Execution time Memory
1093857 2024-09-27T18:30:08 Z lambd47 Type Printer (IOI08_printer) C++14
20 / 100
47 ms 54876 KB
#include<bits/stdc++.h>
using namespace std;

const int MX=5e5+1;

int trie[MX][27];
char letra[MX];
bool ultimo[MX];
int tempo=0;

void add(string s, bool flag){
    int idat=0;
    for(auto c: s){
        int nat=c-'a';
        if(trie[idat][nat]!=-1){
            idat=trie[idat][nat];
        }
        else{
            trie[idat][nat]=++tempo;
            idat=tempo;
            letra[idat]=c;
        }
        if(flag)ultimo[idat]=1;
    }
}
int n;
bool acabou=0;
int cnt=0;
void dfs(int node){
    if(node!=0)cout<<letra[node]<<"\n";
    int esp=-1;
    bool folha=1;
    for(int i=0;i<26;i++){
        if(trie[node][i]==-1)continue;
        folha=0;
        if(ultimo[trie[node][i]]){
            esp=trie[node][i];
            continue;
        }
        dfs(trie[node][i]);
    }
    if(esp!=-1){
        dfs(esp);
    }
    if(folha){cout<<"P\n";cnt++;}
    if(cnt!=n && !ultimo[node])cout<<"-\n";
}



int main(){
    cin>>n;
    for(int i=0;i<MX;i++){
        for(int j=0;j<27;j++)trie[i][j]=-1;
    }
    vector<string> vec(n);
    int especial=0;
    int maior=0;
    for(int i=0;i<n;i++){cin>>vec[i];
        if(maior<vec[i].size()){
            maior=vec[i].size();
            especial=i;
        }
    }
    for(int i=0;i<n;i++){
        if(especial==i){
            add(vec[i],1);
        }
        else{
            add(vec[i],0);
        }
    }
    cout<<2*(tempo)-maior+n<<"\n";
    dfs(0);



}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         if(maior<vec[i].size()){
      |            ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 53084 KB Output is correct
2 Correct 24 ms 53084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 53076 KB Output is correct
2 Correct 22 ms 53080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 53084 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 53328 KB Output is correct
2 Incorrect 26 ms 53072 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 53076 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 53328 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 53340 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 53840 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 54876 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 54528 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -