Submission #656317

#TimeUsernameProblemLanguageResultExecution timeMemory
656317NakeebType Printer (IOI08_printer)C++17
0 / 100
43 ms2380 KiB
#include<bits/stdc++.h> using namespace std; string c; bool cmp(string &a,string &b) { int cnt1=a.size(),cnt2=b.size(); for(int i=0;i<(int)a.size();i++) if(a[i]!=c[i]) cnt1=i; for(int i=0;i<(int)b.size();i++) if(b[i]!=c[i]) cnt2=i; if(cnt1==cnt2) return a<b; return cnt1<cnt2; } int main() { int n; int mx=0; cin>>n; string s[n]; for(int i=0;i<n;i++) { cin>>s[i]; if((int)s[i].size()>mx||((int)s[i].size()==mx&&s[i]>c)) mx=(int)s[i].size(),c=s[i]; } vector<char>ans; sort(s,s+n,cmp); for(int i=0;i<(int)s[0].size();i++) ans.push_back(s[0][i]); ans.push_back('p'); for(int i=1;i<n;i++) { if(s[i-1].size()>s[i].size()) for(int i=0;i<(int)s[i-1].size()-(int)s[i].size();i++) ans.push_back('-'); int sz=min((int)s[i-1].size(),(int)s[i].size()); int k=0; for(;k<sz;k++) if(s[i-1][k]!=s[i][k]) break; k--; for(int j=k;j<sz-1;j++) ans.push_back('-'); k++; for(;k<(int)s[i].size();k++) ans.push_back(s[i][k]); ans.push_back('P'); } cout<<ans.size()<<endl; for(auto i:ans) cout<<i<<'\n'; }
#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...