# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239575 | 2020-06-16T13:01:35 Z | Autoratch | Type Printer (IOI08_printer) | C++14 | 74 ms | 60664 KB |
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int n; string s[N],ans; int tree[N][26],mxch[N],mxs[N]; int cur[N],cnt; vector<string> ls; void add(string s) { int now = 0; for(char c : s) { if(s.length()>mxs[now]) mxs[now] = s.length(),mxch[now] = c-'a'; if(tree[now][c-'a']) now = tree[now][c-'a']; else tree[now][c-'a'] = ++cnt,now = cnt; } cur[now]++; } void solve(int now,string cu) { while(cur[now]--) ls.push_back(cu); for(int i = 0;i < 26;i++) if(tree[now][i]) { if(mxs[now] and mxch[now]==i) continue; solve(tree[now][i],cu+(char)(i+'a')); } if(mxs[now]) solve(tree[now][mxch[now]],cu+(char)(mxch[now]+'a')); } void ch(string a,string b) { int sm = 0; for(int i = 0,j = 0;i < a.length() and j < b.length() and a[i]==b[j];i++,j++) sm++; for(int i = 0;i < a.length()-sm;i++) ans+='-'; for(int i = sm;i < b.length();i++) ans+=b[i]; ans+='P'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1;i <= n;i++) cin >> s[i],add(s[i]); solve(0,""); for(int i = 0;i < ls.size();i++) { string a = "",b = ls[i]; if(i) a = ls[i-1]; ch(a,b); } cout << ans.length() << '\n'; for(char c : ans) cout << c << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 6656 KB | Output is correct |
2 | Correct | 9 ms | 6656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 6656 KB | Output is correct |
2 | Correct | 10 ms | 6656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 6656 KB | Output is correct |
2 | Correct | 10 ms | 6656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 6656 KB | Output is correct |
2 | Correct | 12 ms | 6656 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 6656 KB | Output is correct |
2 | Correct | 11 ms | 7044 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 7552 KB | Output is correct |
2 | Correct | 14 ms | 7680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 18 ms | 9856 KB | Output is correct |
2 | Correct | 30 ms | 13556 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 14844 KB | Output is correct |
2 | Correct | 20 ms | 9124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 74 ms | 27240 KB | Output is correct |
2 | Runtime error | 73 ms | 60664 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 66 ms | 22896 KB | Output is correct |
2 | Runtime error | 65 ms | 60536 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
3 | Halted | 0 ms | 0 KB | - |