Submission #980628

#TimeUsernameProblemLanguageResultExecution timeMemory
980628enkhochirType Printer (IOI08_printer)C++14
100 / 100
98 ms100884 KiB
#include<bits/stdc++.h> using namespace std; #define int long long int n; string s[25005]; int trie[500005][27]; int longest=0; int cnt=1; string ans=""; bool islong[500005], isend[500005]; void dfs(int node){ if(isend[node]){ ans+='P'; // return; } int tmp=-1; for(int i=0; i<26; i++){ if(trie[node][i]>0){ if(islong[trie[node][i]]){ tmp=i; } else{ char tmpchar='a'+i; ans+=tmpchar; dfs(trie[node][i]); ans+='-'; } } } if(tmp!=-1){ char tmpchar='a'+tmp; ans+=tmpchar; dfs(trie[node][tmp]); ans+='-'; } } signed main(){ ios::sync_with_stdio(0); cin.tie(NULL); cin>>n; for(int i=0; i<n; i++){ cin>>s[i]; int sz=s[i].size(); longest=max(longest,sz); } for(int i=0; i<n; i++){ bool flag=0; if(s[i].size()==longest){ longest=-1; flag=1; } int cur=0; for(int j=0; j<s[i].size(); j++){ if(trie[cur][s[i][j]-'a']==0){ trie[cur][s[i][j]-'a']=cnt; cnt++; } // islong[cur]=flag; islong[trie[cur][s[i][j]-'a']]|=flag; cur=trie[cur][s[i][j]-'a']; } isend[cur]=1; } dfs(0); 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 'int main()':
printer.cpp:48:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   48 |   if(s[i].size()==longest){
      |      ~~~~~~~~~~~^~~~~~~~~
printer.cpp:53:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(int j=0; j<s[i].size(); j++){
      |                ~^~~~~~~~~~~~
printer.cpp:70:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |  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...