Submission #235613

#TimeUsernameProblemLanguageResultExecution timeMemory
235613Haunted_CppType Printer (IOI08_printer)C++17
30 / 100
159 ms83820 KiB
/** * author: Duarte Nobrega * created: 28.05.2020 **/ #include <bits/stdc++.h> using namespace std; struct Node { Node *abc[26]; int sub = 0; bool is_word = false; } *root, *cur; void inserir (const string &w) { cur = root; for (int i = 0; i < (int) w.size(); i++) { if (cur -> abc[w[i] - 'a'] == nullptr) { cur -> abc[w[i] - 'a'] = new Node; } cur = cur -> abc[w[i] - 'a']; } cur -> is_word = true; } vector<char> ans; void dfs (Node *current) { if (current -> is_word) ans.emplace_back('P'); vector< pair<int, int> > ordem; for (int i = 0; i < 26; i++) { if (current -> abc[i] != nullptr) { ordem.emplace_back( current -> abc[i] -> sub, i ); } } sort (ordem.begin(), ordem.end()); for (auto to : ordem) { ans.emplace_back(char ('a' + to.second)); dfs (current -> abc[to.second]); } ans.emplace_back('-'); } int get_size (Node *current) { int res = 1; for (int i = 0; i < 26; i++) { if (current -> abc[i] != nullptr) { res += get_size (current -> abc[i]); } } current -> sub = res; return res; } int main () { ios::sync_with_stdio(0); cin.tie(0); root = new Node; int n; cin >> n; for (int i = 0; i < n; i++) { string w; cin >> w; inserir (w); } get_size (root); dfs (root); while (ans.back() == '-') ans.pop_back(); cout << (int) ans.size() << '\n'; for (auto to : ans) cout << to << '\n'; 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...