Submission #855098

#TimeUsernameProblemLanguageResultExecution timeMemory
855098vjudge1Type Printer (IOI08_printer)C++14
0 / 100
195 ms262144 KiB
#include<bits/stdc++.h> using namespace std; const int sig=26,nn=25000; struct node{ int ch[sig]; bool mark,end; }t[nn*20]; int sz=0; void insert(const string& s){ int u=0; for(char c:s){ int d=c-'a',&cu=t[u].ch[d]; if(!cu) cu+=sz; u=cu; } t[u].end=true; } void dfs(int u,string& ans){ const node& x=t[u]; if(x.end) ans+='p'; int mi=-1; for(int i=0;i<sig;i++){ int v=x.ch[i]; if(!v) continue; if(t[v].mark) mi=i; else ans+=i+'a',dfs(v,ans); } if(mi=-1) ans+=mi+'a',dfs(x.ch[mi],ans); ans+='-'; } int main(){ int n; cin>>n; string s,l; for(int i=0;i<n;i++){ cin>>s,insert(s); if(s.length()>l.length()) l=s; } for(size_t i=0,u=0;i<l.size();i++) u=t[u].ch[l[i]-'a'],t[u].mark=true; s.clear(),dfs(0,s); while(s.back()=='-') s.pop_back(); cout<<s.size()<<'\n'; for(char c:s) cout<<c<<"\n"; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void dfs(int, std::string&)':
printer.cpp:30:7: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   30 |  if(mi=-1)
      |     ~~^~~
printer.cpp:31:26: warning: array subscript -1 is below array bounds of 'const int [26]' [-Warray-bounds]
   31 |   ans+=mi+'a',dfs(x.ch[mi],ans);
      |                   ~~~~~~~^
printer.cpp:5:6: note: while referencing 'node::ch'
    5 |  int ch[sig];
      |      ^~
#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...