Submission #730700

#TimeUsernameProblemLanguageResultExecution timeMemory
730700lucriType Printer (IOI08_printer)C++17
100 / 100
126 ms53988 KiB
#include <bits/stdc++.h> using namespace std; int n,a[650010][30],ans,nr; char lmax,c[25],cmax[25]; void adauga() { int l=strlen(c),nod=0; for(int i=0;i<l;++i) { if(a[nod][c[i]-'a']) nod=a[nod][c[i]-'a']; else { a[nod][c[i]-'a']=++nr; nod=nr; } } ++a[nod][26]; } void elimina(int str,int nod,bool rb) { for(int i=0;i<26;++i) { if(a[nod][i]&&(rb==false||rb==true&&i+'a'!=cmax[str])) { cout<<(char)(i+'a')<<'\n'; elimina(str+1,a[nod][i],false); } } while(a[nod][26]--) cout<<"P\n"; if(rb==true) { if(str<lmax) { cout<<cmax[str]<<'\n'; elimina(str+1,a[nod][cmax[str]-'a'],true); } } else cout<<"-\n"; } int main() { cin>>n; while(n--) { cin>>c; adauga(); ++ans; if(strlen(c)>lmax) { lmax=strlen(c); for(int i=0;i<lmax;++i) cmax[i]=c[i]; } } cout<<nr*2+ans-lmax<<'\n'; elimina(0,0,true); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void elimina(int, int, bool)':
printer.cpp:24:43: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   24 |         if(a[nod][i]&&(rb==false||rb==true&&i+'a'!=cmax[str]))
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:51:21: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'char' [-Wsign-compare]
   51 |         if(strlen(c)>lmax)
      |            ~~~~~~~~~^~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...