Submission #855061

#TimeUsernameProblemLanguageResultExecution timeMemory
855061vjudge1Type Printer (IOI08_printer)C++17
10 / 100
35 ms19656 KiB
#include <bits/stdc++.h> using namespace std; bool vis[2000005], vis1[2000005]; int t[2000005][26];//o --> ch 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']) t[o][s[i] - 'a'] = ++n, o = n; else o = t[o][s[i] - 'a']; } vis1[o] = 1; // 结尾 return; } void dfs(int o, vector<char>& ans) { for(int i=0;i<26;i++){ if(t[o][i]!=0){ ans.push_back(i+'a'); dfs(t[o][i],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...