제출 #1094393

#제출 시각아이디문제언어결과실행 시간메모리
1094393lenronType Printer (IOI08_printer)C++17
10 / 100
144 ms27740 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int node_num=0,pcount=0; vector<vector<int>> trie(100000,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...