# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
248425 | 2020-07-12T12:32:54 Z | DavidDamian | Type Printer (IOI08_printer) | C++11 | 109 ms | 19752 KB |
#include <bits/stdc++.h> using namespace std; struct node{ int bucket[27]; int cnt; }; node trie[500005]; int act=0; void trieInsert(string s) { int u=0; for(int i=0;i<s.size();i++){ int letter=s[i]-'a'; if(trie[u].bucket[letter]==0) trie[u].bucket[letter]=++act; u=trie[u].bucket[letter]; } trie[u].cnt++; } int subtreeSize[500005]; void computeSize(int u,int depth) { subtreeSize[u]=depth; for(int i=0;i<'z'-'a';i++){ if(trie[u].bucket[i]!=0){ int v=trie[u].bucket[i]; computeSize(v,depth+1); subtreeSize[u]=max(subtreeSize[u],subtreeSize[v]); } } } struct order { int id,w; }; bool byW(order a,order b) { return a.w<b.w; } string ans; int printed_words=0; int n; void dfs(int u) { order A[27]; if(trie[u].cnt){ printed_words++; ans.push_back('P'); } for(int i=0;i<27;i++){ A[i].id=i; int v=trie[u].bucket[i]; A[i].w=(v!=0)? subtreeSize[v] : INT_MAX; } sort(A,A+27,byW); for(int i=0;i<'z'-'a';i++){ if(A[i].w==INT_MAX) continue; ans.push_back(char(A[i].id+'a')); int v=trie[u].bucket[ A[i].id ]; dfs(v); } if(printed_words<n) ans.push_back('-'); } int main() { cin>>n; for(int i=1;i<=n;i++){ string s; cin>>s; trieInsert(s); } computeSize(0,0); dfs(0); cout<<ans.size()<<'\n'; for(char c: ans){ cout<<c<<'\n'; } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 1 ms | 384 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Incorrect | 0 ms | 384 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 384 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 1152 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 3360 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 47 ms | 8204 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 109 ms | 19752 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 89 ms | 15508 KB | too many deletions |
2 | Halted | 0 ms | 0 KB | - |