Submission #1103914

#TimeUsernameProblemLanguageResultExecution timeMemory
1103914dubabubaType Printer (IOI08_printer)C++14
60 / 100
1061 ms98828 KiB
#include <bits/stdc++.h> using namespace std; template<typename T> void maxer(T &MAX, T CMP) { if(MAX < CMP) MAX = CMP; } template<typename T> void miner(T &MIN, T CMP) { if(MIN > CMP) MIN = CMP; } const int mxc = 26; struct trie { trie *chi[mxc]; int cnt, len; trie() { for(int i = 0; i < mxc; i++) chi[i] = NULL; cnt = len = 0; } }; trie *root = new trie(); void insert(string s) { trie *cur = root; for(char c : s) { if(!cur->chi[c - 'a']) cur->chi[c - 'a'] = new trie(); maxer(cur->len, (int)s.size()); cur = cur->chi[c - 'a']; } cur->len = s.size(); cur->cnt++; } vector<char> ans; void solve(trie *cur) { while(cur->cnt) { ans.push_back('P'); cur->cnt--; } for(int i = 0; i < mxc; i++) { trie *nxt = cur->chi[i]; if(nxt == NULL) continue; if(nxt->len == cur->len) continue; ans.push_back('a' + i); solve(nxt); ans.push_back('-'); } for(int i = 0; i < mxc; i++) { trie *nxt = cur->chi[i]; if(nxt == NULL) continue; if(nxt->len != cur->len) continue; ans.push_back('a' + i); solve(nxt); ans.push_back('-'); } } int main() { int n; cin >> n; string s; for(int i = 0; i < n; i++) { cin >> s; insert(s); } solve(root); while(ans.back() != 'P') ans.pop_back(); cout << ans.size() << endl; for(char c : ans) cout << c << endl; return 0; }
#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...