Submission #875462

#TimeUsernameProblemLanguageResultExecution timeMemory
875462RandomChickenType Printer (IOI08_printer)C++11
10 / 100
35 ms16360 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; #define f0r(i,n) for(ll i = 0; i<(ll)(n); i++) #define fir(it,d) for(auto it = d.begin(); it!=d.end(); it++) struct node{ char c; ll endings; vll crs; }; vector<node> trie(1,{'@',0,vll(0)}); vector<char> ans; void addString(string s){ ll tId = 0; f0r(sId,s.size()){ bool found = false; f0r(i,trie[tId].crs.size()){ if(trie[trie[tId].crs[i]].c==s[sId]){ tId = trie[tId].crs[i]; found = true; break; } } if(!found){ trie[tId].crs.push_back(trie.size()); tId = trie.size(); trie.push_back({s[sId],0,vll(0)}); } } trie[tId].endings++; } void dfs(ll id){ if(id) ans.push_back(trie[id].c); f0r(i,trie[id].crs.size()){ ll cr = trie[id].crs[i]; dfs(cr); } f0r(i,trie[id].endings) ans.push_back('P'); if(id) ans.push_back('-'); } bool compSize(string a, string b){ return(a.size()<b.size()); } int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; vector<string> inps(n); f0r(i,n){ cin>>inps[i]; } sort(inps.begin(),inps.end(),compSize); f0r(i,n){ addString(inps[i]); } dfs(0); while(ans.back()=='-'){ ans.pop_back(); } cout<<ans.size()<<"\n"; f0r(i,ans.size()){ cout<<ans[i]<<"\n"; } }
#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...