# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226389 | 2020-04-23T16:45:52 Z | shahriarkhan | Type Printer (IOI08_printer) | C++14 | 1000 ms | 50228 KB |
#include<bits/stdc++.h> using namespace std ; const int maxN = 5e5 + 5 ; int nex[maxN][26] , ed[maxN] , mark[maxN] , sz ; vector<char> ans ; void insert_string(string &s) { int v = 0 , siz = s.size() ; for(int i = 0 ; i < siz ; ++i) { int c = s[i] - 'a' ; if(!nex[v][c]) nex[v][c] = ++sz ; v = nex[v][c] ; } ++ed[v] ; } void dfs(int ind) { int marked = 0 , in ; while(ed[ind]) ans.push_back('P') , --ed[ind] ; for(int i = 0 ; i < 26 ; ++i) { if(mark[nex[ind][i]]) { marked = nex[ind][i] , in = i ; continue ; } if(nex[ind][i]) { char c = 'a' + i ; ans.push_back(c) ; dfs(nex[ind][i]) ; } } if(marked) { char c = 'a' + in ; ans.push_back(c) ; dfs(marked) ; } if(ind) ans.push_back('-') ; } bool cmp(string &s , string &t) { return s.size()<t.size() ; } int main() { int n ; scanf("%d",&n) ; vector<string> vs ; for(int i = 0 ; i < n ; ++i) { string s ; cin>>s ; vs.push_back(s) ; } sort(vs.begin(),vs.end(),cmp) ; for(int i = 0 ; i < n - 1 ; ++i) insert_string(vs[i]) ; int v = 0 , siz = vs[n-1].size() ; for(int i = 0 ; i < siz ; ++i) { int c = vs[n-1][i] - 'a' ; if(!nex[v][c]) nex[v][c] = ++sz ; v = nex[v][c] ; mark[v] = 1 ; } ++ed[v] ; dfs(0) ; int siza = ans.size() ; while(ans[siza-1]!='P') --siza ; printf("%d\n",siza) ; for(int i = 0 ; i < siza ; ++i) cout<<ans[i]<<endl ; return 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 4 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 512 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 432 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 384 KB | Output is correct |
2 | Correct | 21 ms | 768 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 1152 KB | Output is correct |
2 | Correct | 41 ms | 1408 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 113 ms | 3320 KB | Output is correct |
2 | Correct | 223 ms | 6772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 278 ms | 8044 KB | Output is correct |
2 | Correct | 93 ms | 2296 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 669 ms | 19668 KB | Output is correct |
2 | Execution timed out | 1100 ms | 42440 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 571 ms | 15696 KB | Output is correct |
2 | Execution timed out | 1092 ms | 50228 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |