# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
365093 | 2021-02-10T21:37:07 Z | Ahmad_Hasan | Type Printer (IOI08_printer) | C++17 | 188 ms | 70104 KB |
#include <bits/stdc++.h> #define int long long /** |||||||||| ||||| ||||| |||||||||| ||||||||||||| ||||| ||||| ||||| |||| |||||| ||||| ||||| ||||| ||||||||||||||||| ||||||||||||||| |||||||||| ||||||||||||||||||| ||||||||||||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| ||||| |||||||||| AHMED;HASSAN;SAEED; */ using namespace std; vector<char>ans; struct trie{ trie* exit[26]; int cnt[26]; bool leaf=0; trie(){ memset(exit,0,sizeof(exit)); memset(cnt,0,sizeof(cnt)); } int insert(string &s,int cr=0){ if(cr==s.size()){ leaf=1; int mx=-1; for(int i=0;i<26;i++){ mx=max(mx,cnt[i]); } return mx+1; } if(exit[s[cr]-'a']==0) exit[s[cr]-'a']=new trie; cnt[s[cr]-'a']=exit[s[cr]-'a']->insert(s,cr+1); int mx=-1; for(int i=0;i<26;i++){ mx=max(mx,cnt[i]); } return mx+1; } void print(){ vector<pair<int,int> >vps(26); for(int i=0;i<26;i++){ vps[i]={cnt[i],i}; } sort(vps.begin(),vps.end()); for(int j=0;j<26;j++){ int i=vps[j].second; if(exit[i]!=0){ ///cout<<(char)('a'+i)<<'\n'; ans.push_back((char)('a'+i)); exit[i]->print(); } } if(leaf){ ///cout<<'P'<<'\n'; ans.push_back('P'); } ///cout<<'-'<<'\n'; ans.push_back('-'); } }; int32_t main() { trie tr; int n; cin>>n; vector<string>vs(n); for(int i=0;i<n;i++){ cin>>vs[i]; tr.insert(vs[i]); } tr.print(); while(ans.back()=='-')ans.pop_back(); cout<<ans.size()<<'\n'; for(int i=0;i<ans.size();i++) cout<<ans[i]<<'\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 364 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Incorrect | 1 ms | 364 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 620 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 3196 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 11244 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 62 ms | 28008 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 188 ms | 70104 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 130 ms | 54968 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |