# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236858 | 2020-06-03T15:15:40 Z | keta_tsimakuridze | Type Printer (IOI08_printer) | C++14 | 165 ms | 78512 KB |
#include<bits/stdc++.h> using namespace std; int k,n,i,cur,f[1000005],endd[1000005],c,ch; vector< pair<char,int> >V[1000005],aft[1000005]; string ans; char s[25],s1[25]; void add(string s){ int u=0; for(i=0;i<s.size();i++){ int ff=0; for(int j=0;j<aft[u].size();j++) if(aft[u][j].first==s[i]){ ff=1;c=aft[u][j].second;break;} if(ff==0){ cur++; aft[u].push_back({s[i],cur}); c=cur; V[u].push_back({s[i],cur}); } u=c; } endd[u]=1; } void check(string s){ int u=0; for(i=0;i<s.size();i++){ for(int j=0;j<aft[u].size();j++) if(aft[u][j].first==(int)s[i]){ c=aft[u][j].second;break;} f[c]=1; u=c; } } void dfs(int u){ if(endd[u]!=0) ans+='P'; for(int i=0;i<V[u].size();i++){ if(f[V[u][i].second]) continue; ans+=V[u][i].first; dfs(V[u][i].second); } for(int i=0;i<V[u].size();i++){ if(f[V[u][i].second]){ ans+=V[u][i].first; dfs(V[u][i].second); } } ans+='-'; } int main(){ scanf("%d" , &n); for(k=1;k<=n;k++){ scanf("%s", s); if(strlen(s) > strlen(s1)){ strcpy(s1 , s); } add(s); } check(s1); dfs(0); i=ans.size()-1; while(ans[i]=='-'){ i--; } printf("%d\n" , i + 1); for(k=0;k<=i;k++){ printf("%c\n",ans[k]); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47352 KB | Output is correct |
2 | Correct | 32 ms | 47356 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47360 KB | Output is correct |
2 | Correct | 32 ms | 47352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47360 KB | Output is correct |
2 | Correct | 31 ms | 47232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47360 KB | Output is correct |
2 | Correct | 33 ms | 47360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47352 KB | Output is correct |
2 | Correct | 34 ms | 47616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 34 ms | 47736 KB | Output is correct |
2 | Correct | 34 ms | 47864 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 41 ms | 49144 KB | Output is correct |
2 | Correct | 48 ms | 51064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 51848 KB | Output is correct |
2 | Correct | 40 ms | 48376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 87 ms | 58516 KB | Output is correct |
2 | Correct | 142 ms | 73520 KB | Output is correct |
3 | Correct | 95 ms | 60564 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 55700 KB | Output is correct |
2 | Correct | 165 ms | 78512 KB | Output is correct |
3 | Correct | 101 ms | 62484 KB | Output is correct |
4 | Correct | 139 ms | 76848 KB | Output is correct |