Submission #676658

#TimeUsernameProblemLanguageResultExecution timeMemory
676658QwertyPiType Printer (IOI08_printer)C++14
90 / 100
1018 ms62404 KiB
#include <bits/stdc++.h> using namespace std; const int SIGMA = 26; int ncnt = 0; struct node{ int nxt[SIGMA] = {}; bool word = false; int heavy = -1; node() {} int extend(int c){ if(!nxt[c]) nxt[c] = ++ncnt; return nxt[c]; } int extend_heavy(int c){ heavy = c; return nxt[c]; } }; const int MAXN = 25011; node trie[MAXN * 21]; string ans; void dfs(int root){ if(trie[root].word) ans.push_back('P'); for(int c = 0; c < SIGMA; c++){ if(trie[root].nxt[c] && trie[root].heavy != c){ ans.push_back('a' + c); dfs(trie[root].nxt[c]); ans.push_back('-'); } } if(trie[root].heavy != -1){ ans.push_back('a' + trie[root].heavy); dfs(trie[root].nxt[trie[root].heavy]); ans.push_back('-'); } } int root = 0; int main(){ cin.tie(0); cout.tie(0)->sync_with_stdio(false); int n; cin >> n; vector<string> vs; for(int i = 0; i < n; i++){ string s; cin >> s; vs.push_back(s); int x = root; for(auto c : s){ x = trie[x].extend(c - 'a'); } trie[x].word = true; } int idx = 0; for(int i = 1; i < n; i++){ if(vs[i].size() > vs[idx].size()){ idx = i; } } { int x = root; for(auto c : vs[idx]){ x = trie[x].extend_heavy(c - 'a'); } } dfs(root); while(ans.back() == '-') ans.pop_back(); cout << ans.size() << endl; for(auto c : ans) cout << c << endl; }
#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...