# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226381 | 2020-04-23T16:20:29 Z | shahriarkhan | Type Printer (IOI08_printer) | C++14 | 696 ms | 18904 KB |
#include<bits/stdc++.h> using namespace std ; const int maxN = 5e5 + 5 ; int nex[maxN][26] , 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] ; } } void dfs(int ind) { int p = 0 , marked = 0 , in ; for(int i = 0 ; i < 26 ; ++i) { if(mark[nex[ind][i]]) { marked = nex[ind][i] , in = i ; continue ; } if(nex[ind][i]) { p = 1 ; char c = 'a' + i ; ans.push_back(c) ; dfs(nex[ind][i]) ; } } if(marked) { p = 1 ; char c = 'a' + in ; ans.push_back(c) ; dfs(marked) ; } if(!p) ans.push_back('P') ; 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 ; } 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 | 4 ms | 256 KB | Output is correct |
2 | Correct | 4 ms | 256 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 | Incorrect | 5 ms | 384 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Incorrect | 5 ms | 384 KB | didn't print every word |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 384 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 34 ms | 1152 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 116 ms | 3192 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 274 ms | 7804 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 696 ms | 18904 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 543 ms | 15320 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |