Submission #540681

# Submission time Handle Problem Language Result Execution time Memory
540681 2022-03-21T11:42:03 Z csamoila Type Printer (IOI08_printer) C++17
0 / 100
60 ms 71536 KB
#include <bits/stdc++.h>

using namespace std;

int N;
string V[101];

struct TrieNode{
    int nrcuv,nrfii;
    TrieNode *fii[26];
    TrieNode(){
        nrcuv=nrfii=0;
        for(int i=0;i<26;i++)
            fii[i]=0;
    }
};

TrieNode *root = new TrieNode;

void inserare(TrieNode *nod,char *s){
    if(*s==0){
        nod->nrcuv++;
        return;
    }
    if(nod->fii[*s-'a']==0){
        nod->nrfii++;
        nod->fii[*s-'a'] = new TrieNode;
    }

    inserare(nod->fii[*s-'a'],s+1);
}

char cuvmax[21];

int rez;
int cont;

string S;

void f(TrieNode *nod,string s,char *cuv){
    int p;
    for(int i=0;i<26;i++){
        if(nod->fii[i]==0) continue;
        if((char)(i+'a')==*cuv){
            p=i;
            continue;
        }
        S+=(char)(i+'a');
        if(nod->fii[i]->nrcuv!=0)
            S+='P',nod->fii[i]->nrcuv=0,cont++;
        f(nod->fii[i],s+(char)(i+'a'),cuv+1);
        if(cont<N) S+='-';
    }
    if(nod->fii[p]==0) return;
    S+=(char)(p+'a');
    if(nod->fii[p]->nrcuv!=0)
        S+='P',cont++;
    f(nod->fii[p],s+(char)(p+'a'),cuv+1);
    if(cont<N) S+='-';
}

int main()
{
    cin >> N;
    for(int i=1;i<=N;i++){
        char s[21];
        cin >> s;
        inserare(root,s);
        if(strlen(s)>strlen(cuvmax))
            strcpy(cuvmax,s);
    }
    f(root,"",cuvmax);
    cout << S.size() << '\n';
    for(auto it:S) cout << it << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'void f(TrieNode*, std::string, char*)':
printer.cpp:55:16: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   55 |     S+=(char)(p+'a');
      |              ~~^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 472 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 564 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 3340 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 11436 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 28500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 60 ms 71536 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 48 ms 55780 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -