Submission #855085

#TimeUsernameProblemLanguageResultExecution timeMemory
855085vjudge1Type Printer (IOI08_printer)C++14
90 / 100
1052 ms55228 KiB
#include<bits/stdc++.h> #define _for(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int N=5e5+5,M=30; int A[N][M],num=0,maxn=0; bool B[N]; string maxs; void jr(string &s) { int l=s.size(),now=0; _for(i,0,l-1) { char x=s[i]; if(!A[now][x-'a'])A[now][x-'a']=++num; now=A[now][x-'a']; } B[now]=1; } void ss(int now,string &ans,int d,bool pd) { if(B[now])ans+='P'; char x=maxs[d]; _for(i,0,25) { if(pd&&i+'a'==x)continue; if(A[now][i]) { ans+=(char)(i+'a'); ss(A[now][i],ans,d+1,0); ans+='-'; } } if(pd&&A[now][x-'a']) { ans+=x; ss(A[now][x-'a'],ans,d+1,1); ans+='-'; } } int main() { ios::sync_with_stdio(false),cin.tie(0); int n; cin>>n; _for(i,1,n) { string x; cin>>x; if(x.size()>maxn)maxn=x.size(),maxs=x; jr(x); } string ans=""; ss(0,ans,0,1); int r=ans.size()-1; while(ans[r]=='-')r--; cout<<r+1<<endl; _for(i,0,r)cout<<ans[i]<<endl; return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:49:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   49 |   if(x.size()>maxn)maxn=x.size(),maxs=x;
      |      ~~~~~~~~^~~~~
#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...