# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093859 | 2024-09-27T18:38:04 Z | lambd47 | Type Printer (IOI08_printer) | C++14 | 82 ms | 58196 KB |
#include<bits/stdc++.h> using namespace std; const int MX=5e5+7; int trie[MX][27]; char letra[MX]; bool ultimo[MX]; bool acabou[MX]; int tempo=0; void add(string s, bool flag){ int idat=0; for(auto c: s){ int nat=c-'a'; if(trie[idat][nat]!=-1){ idat=trie[idat][nat]; } else{ trie[idat][nat]=++tempo; idat=tempo; letra[idat]=c; } if(flag)ultimo[idat]=1; } acabou[idat]=1; } int n; int cnt=0; void dfs(int node){ if(node!=0)cout<<letra[node]<<"\n"; int esp=-1; bool folha=1; if(acabou[node]){cout<<"P\n";cnt++;} for(int i=0;i<26;i++){ if(trie[node][i]==-1)continue; folha=0; if(ultimo[trie[node][i]]){ esp=trie[node][i]; continue; } dfs(trie[node][i]); } if(esp!=-1){ dfs(esp); } if(cnt!=n && !ultimo[node])cout<<"-\n"; } int main(){ cin>>n; for(int i=0;i<MX;i++){ for(int j=0;j<27;j++)trie[i][j]=-1; } vector<string> vec(n); int especial=0; int maior=0; for(int i=0;i<n;i++){cin>>vec[i]; if(maior<vec[i].size()){ maior=vec[i].size(); especial=i; } } for(int i=0;i<n;i++){ if(especial==i){ add(vec[i],1); } else{ add(vec[i],0); } } cout<<2*(tempo)-maior+n<<"\n"; dfs(0); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 53248 KB | Output is correct |
2 | Correct | 24 ms | 53084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 53092 KB | Output is correct |
2 | Correct | 24 ms | 53080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 22 ms | 53076 KB | Output is correct |
2 | Correct | 24 ms | 53084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 53140 KB | Output is correct |
2 | Correct | 25 ms | 53092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 53168 KB | Output is correct |
2 | Correct | 25 ms | 53088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 53336 KB | Output is correct |
2 | Correct | 26 ms | 53344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 28 ms | 53336 KB | Output is correct |
2 | Correct | 33 ms | 53736 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 54104 KB | Output is correct |
2 | Correct | 29 ms | 53852 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 46 ms | 55124 KB | Output is correct |
2 | Correct | 71 ms | 57384 KB | Output is correct |
3 | Correct | 56 ms | 56432 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 42 ms | 54864 KB | Output is correct |
2 | Correct | 82 ms | 58192 KB | Output is correct |
3 | Correct | 62 ms | 56916 KB | Output is correct |
4 | Correct | 72 ms | 58196 KB | Output is correct |