Submission #683907

#TimeUsernameProblemLanguageResultExecution timeMemory
683907abcdehelloType Printer (IOI08_printer)C++17
80 / 100
1091 ms147844 KiB
#include <bits/stdc++.h> using namespace std; struct node{ int ch; bool print=false,lst=false; vector<int> nxt; }; node trie[1000050]; int n,nxt=1; vector<string> ss,longest; vector<char> ans; void dfs(int u){ cerr << "trav " << u << endl; if (u>0) ans.push_back(trie[u].ch); if (trie[u].print) ans.push_back('P'); int lst=-1; for (int i=0;i<26;i++){ if (trie[u].nxt[i]==-1) continue; if (trie[trie[u].nxt[i]].lst){ lst=trie[u].nxt[i]; continue; } dfs(trie[u].nxt[i]); } if (lst>0) dfs(lst); else ans.push_back('-'); } bool comp(string a,string b){ if (a.length()!=b.length()) return a.length()<b.length(); return a<b; } int main(){ for (int i=0;i<1000050;i++){ trie[i].nxt.resize(26); for (int j=0;j<26;j++){ trie[i].nxt[j]=-1; } } cin >> n; for (int i=0;i<n;i++){ string s; cin >> s; ss.push_back(s); int cur=0; for (int j=0;j<s.length();j++){ if (trie[cur].nxt[s[j]-'a']==-1){ trie[cur].nxt[s[j]-'a']=nxt++; trie[nxt-1].ch=s[j]; } cur=trie[cur].nxt[s[j]-'a']; } trie[cur].print=1; } sort(ss.begin(),ss.end(),comp); string lst=ss.back(); int cur=0; for (int i=0;i<lst.length();i++){ cur=trie[cur].nxt[lst[i]-'a']; trie[cur].lst=1; } cerr << endl; dfs(0); ans.pop_back(); cout << ans.size() << "\n"; for (auto i:ans) cout << i << "\n"; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for (int j=0;j<s.length();j++){
      |                ~^~~~~~~~~~~
printer.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for (int i=0;i<lst.length();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...