# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093858 | 2024-09-27T18:35:40 Z | lambd47 | Type Printer (IOI08_printer) | C++14 | 44 ms | 54864 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; 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(acabou[node]){cout<<"P\n";cnt++;} 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 | 23 ms | 53080 KB | Output is correct |
2 | Correct | 24 ms | 53084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 53084 KB | Output is correct |
2 | Correct | 22 ms | 53084 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 23 ms | 53084 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 23 ms | 53236 KB | Output is correct |
2 | Incorrect | 23 ms | 53076 KB | printed invalid word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 53072 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 24 ms | 53332 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 26 ms | 53336 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 31 ms | 53852 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 44 ms | 54864 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 40 ms | 54612 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |