Submission #676654

#TimeUsernameProblemLanguageResultExecution timeMemory
676654QwertyPiType Printer (IOI08_printer)C++14
90 / 100
1050 ms100768 KiB
#include <bits/stdc++.h> using namespace std; const int SIGMA = 26; struct node{ node* nxt[SIGMA]; bool word = false; int heavy = -1; node() { for(int i = 0; i < SIGMA; i++){ nxt[i] = nullptr; } } node* extend(int c){ if(!nxt[c]) nxt[c] = new node(); return nxt[c]; } node* extend_heavy(int c){ heavy = c; return nxt[c]; } }; string ans; void dfs(node *root){ if(root->word) ans.push_back('P'); for(int c = 0; c < SIGMA; c++){ if(root->nxt[c] && root->heavy != c){ ans.push_back('a' + c); dfs(root->nxt[c]); ans.push_back('-'); } } if(root->heavy != -1){ ans.push_back('a' + root->heavy); dfs(root->nxt[root->heavy]); ans.push_back('-'); } } node *root = new node(); 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); node *x = root; for(auto c : s){ x = x->extend(c - 'a'); } x->word = true; } int idx = 0; for(int i = 1; i < n; i++){ if(vs[i].size() > vs[idx].size()){ idx = i; } } { node *x = root; for(auto c : vs[idx]){ x = 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...