Submission #1094392

#TimeUsernameProblemLanguageResultExecution timeMemory
1094392lenronType Printer (IOI08_printer)C++17
10 / 100
2 ms860 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int node_num=0,pcount=0; vector<vector<int>> trie(1000,vector<int>(26,0)); vector<bool> stop(100000,false); vector<char> ans; void insert(string word){ int node=0; for(char c:word){ if(trie[node][c-'a']==0){trie[node][c-'a']=++node_num;pcount++;} node=trie[node][c-'a']; } stop[node]=true; } string s=""; void dfs(int u){ int node=u; if(stop[node]==true){ans.push_back('P');} for(int i=0;i<26;i++){ if(trie[node][i]==0){continue;} ans.push_back(char('a'+i)); pcount--; int v=trie[node][i]; dfs(v); if(pcount==0){return;} ans.push_back('-'); } } void solve(){ ll n;cin>>n; for(int i=0;i<n;i++){ string s;cin>>s; insert(s); } dfs(0); cout<<ans.size()<<endl; for(auto x:ans){cout<<x<<endl;} } int main(){ solve(); }
#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...