# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
236811 | 2020-06-03T12:17:25 Z | nickmet2004 | Type Printer (IOI08_printer) | C++11 | 159 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[22] , s1[22]; 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(){ ios_base::sync_with_stdio(false); 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 | 31 ms | 47360 KB | Output is correct |
2 | Correct | 30 ms | 47352 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 47360 KB | Output is correct |
2 | Correct | 31 ms | 47360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 47360 KB | Output is correct |
2 | Correct | 30 ms | 47360 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 47360 KB | Output is correct |
2 | Correct | 30 ms | 47328 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 47352 KB | Output is correct |
2 | Correct | 31 ms | 47608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47744 KB | Output is correct |
2 | Correct | 34 ms | 48000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 49024 KB | Output is correct |
2 | Correct | 49 ms | 51192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 50 ms | 51720 KB | Output is correct |
2 | Correct | 38 ms | 48504 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 81 ms | 58260 KB | Output is correct |
2 | Correct | 141 ms | 73644 KB | Output is correct |
3 | Correct | 91 ms | 60564 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 76 ms | 55572 KB | Output is correct |
2 | Correct | 159 ms | 78512 KB | Output is correct |
3 | Correct | 105 ms | 62484 KB | Output is correct |
4 | Correct | 140 ms | 76852 KB | Output is correct |