Submission #65047

#TimeUsernameProblemLanguageResultExecution timeMemory
65047TuGSGeReLType Printer (IOI08_printer)C++14
100 / 100
329 ms113172 KiB
#include<bits/stdc++.h> #define ll long long #define mp make_pair #define pub push_back #define pob pop_back #define ss second #define ff first #define ext exit(0) using namespace std; struct trie{ trie *next[26]; ll h,door; trie(){ for(int i=0;i<26;i++) next[i]=NULL; h=-1; door=0; } }; ll n,zr[26]; string s[111111]; vector<pair<ll,ll> >v; vector<char>ans; void insert(trie *root,string s){ for(int i=0;i<s.size();i++){ if(root->next[s[i]-'a']==NULL){ root->next[s[i]-'a']=new trie(); } root=root->next[s[i]-'a']; ll oo=s.size()-i-1; root->door=max(oo,root->door); } root->h=1; } void nem(trie* root){ if(root->h==1) ans.pub('P'); vector<pair<ll,ll> >kkkk; for(int i=0;i<26;i++){ if(root->next[i]!=NULL){ kkkk.pub(mp(root->next[i]->door,i)); } } sort(kkkk.begin(),kkkk.end()); for(int i=0;i<kkkk.size();i++) { ans.pub(kkkk[i].ss+'a'); nem(root->next[kkkk[i].ss]); ans.pub('-'); } } void solv(ll k,trie *root){ root=root->next[k]; ans.pub(char(k+'a')); nem(root); } int main (){ trie *root=new trie(); cin>>n; for(int i=1;i<=n;i++){ cin>>s[i]; ll oo=s[i].size(); zr[s[i][0]-'a']=max(zr[s[i][0]-'a'],oo); insert(root,s[i]); } for(int i=0;i<26;i++) v.pub(mp(zr[i],i)); sort(v.begin(),v.end()); for(int i=0;i<26;i++){ if(v[i].ff)solv(v[i].ss,root),ans.pub('-'); } while(ans.back()=='-') ans.pop_back(); cout<<ans.size()<<"\n"; for(int i=0;i<ans.size();i++){ cout<<ans[i]<<"\n"; } }

Compilation message (stderr)

printer.cpp: In function 'void insert(trie*, std::__cxx11::string)':
printer.cpp:24:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<s.size();i++){
              ~^~~~~~~~~
printer.cpp: In function 'void nem(trie*)':
printer.cpp:43:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<kkkk.size();i++) {
              ~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<ans.size();i++){
              ~^~~~~~~~~~~
#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...