Submission #855067

#TimeUsernameProblemLanguageResultExecution timeMemory
855067vjudge1Type Printer (IOI08_printer)C++17
20 / 100
77 ms138192 KiB
#include <bits/stdc++.h> using namespace std; bool vis[2000005], vis1[2000005]; int t[2000005][26]; int t1[2000005][26]; // o --> ch set<pair<int, int>> v[2000005]; // v[i]--> i的子树{长度,字母} int k, ans1 = 0; struct Trie { int n = 1; void update(string s) { int o = 1; for (int i = 0; i < (int)s.size(); i++) { if (!t[o][s[i] - 'a']) v[o].insert({s.size() - i, s[i] - 'a'}), t[o][s[i] - 'a'] = ++n, t1[o][s[i] - 'a'] = s.size() - i, o = n; else v[o].erase({t1[o][s[i] - 'a'], s[i] - 'a'}), v[o].insert({(t1[o][s[i] - 'a'] += s.size() - i), s[i] - 'a'}), o = t[o][s[i] - 'a']; } vis1[o] = 1; // 结尾 return; } void dfs(int o, vector<char>& ans) { for (auto i : v[o]) { ans.push_back(i.second + 'a'); dfs(t[o][i.second], ans); } if (vis1[o] == 1) ans1++, ans.push_back('P'); if (ans1 != k) ans.push_back('-'); return; } }; int main() { cin >> k; string s; Trie tr; for (int i = 0; i < k; i++) { cin >> s; tr.update(s); } vector<char> ans; tr.dfs(1, ans); cout << ans.size(); cout << "\n"; for (char i : ans) cout << i << "\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...