Submission #739605

#TimeUsernameProblemLanguageResultExecution timeMemory
739605MODDIType Printer (IOI08_printer)C++14
100 / 100
148 ms108360 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair typedef long long ll; typedef pair<long long, long long> pll; typedef pair<int,int> pii; typedef vector<long long> vl; typedef vector<int> vi; template<class T> bool ckmax(T& a, const T& b){return a<b?a=b,1:0;} int n; vector<string> str; struct trie{ trie* children[26]={}; int last = 69, mxd = -1; bool leaf = false; }; void trie_add(trie* root, string s){ trie* cur = root; for(int i = 0; i < s.size(); i++){ int c = s[i] - 'a'; if(cur->children[c] == NULL) cur->children[c] = new trie; if(ckmax(cur->mxd, (int)s.size() - i -1)) cur-> last = c; cur = cur->children[c]; } cur->leaf = true; } vector<char> ans; void dfs(trie* root){ if(root->leaf) ans.pb('P'); for(int i = 0; i < 26; i++){ if(root->children[i] != NULL && i != root->last){ ans.pb(char(i + 'a')); dfs(root->children[i]); } } if(root->last != 69){ ans.pb(char(root->last +'a')); dfs(root->children[root->last]); } ans.pb('-'); } int main(){ cin>>n; str.resize(n); for(int i = 0; i < n; i++) cin>>str[i]; trie t; for(auto i : str){ trie_add(&t, i); } dfs(&t); while(ans.back() == '-') ans.pop_back(); cout<<ans.size()<<endl; for(auto t : ans) cout<<t<<'\n'; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void trie_add(trie*, std::string)':
printer.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i = 0; i < s.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...