# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
655017 | 2022-11-02T15:44:48 Z | happypotato | Type Printer (IOI08_printer) | C++17 | 74 ms | 4612 KB |
#include <bits/stdc++.h> using namespace std; bool cmp1(string &a, string &b) { if (a.length() != b.length()) return a.length() < b.length(); for (int i = 0; i < min(a.length(), b.length()); i++) { if (a[i] != b[i]) return a[i] < b[i]; } return false; } string last; bool cmp2(string &a, string &b) { int cnt1 = a.length(), cnt2 = b.length(); for (int i = 0; i < a.length(); i++) { if (a[i] != last[i]) { cnt1 = i; break; } } for (int i = 0; i < b.length(); i++) { if (b[i] != last[i]) { cnt2 = i; break; } } if (cnt1 != cnt2) return cnt1 < cnt2; return a < b; } vector<char> ans; vector<string> v; void solve() { int n; cin >> n; for (int i = 0; i < n; i++) { string str; cin >> str; v.push_back(str); } sort(v.begin(), v.end(), cmp1); last = v[v.size() - 1]; sort(v.begin(), v.end() - 1, cmp2); string str = ""; int strl = 0; for (int i = 0; i < n; i++) { int vl = v[i].length(); int ptr = 0; while (ptr < min(vl, strl)) { if (str[ptr] == v[i][ptr]) ptr++; else break; } while (str.length() > ptr) { ans.push_back('-'); str.erase(strl - 1, 1); strl--; } for (int j = strl; j < vl; j++) { ans.push_back(v[i][j]); str += v[i][j]; strl++; } ans.push_back('P'); } printf("%d\n", ans.size()); for (char c : ans) printf("%c\n", c); } int main() { int t = 1; // cin >> t; for (int i = 1;i <= t;i++) solve(); } /* */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 2 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 596 KB | Output is correct |
2 | Correct | 11 ms | 988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 1228 KB | Output is correct |
2 | Correct | 13 ms | 952 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 2476 KB | Output is correct |
2 | Correct | 58 ms | 3904 KB | Output is correct |
3 | Correct | 60 ms | 3416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 2364 KB | Output is correct |
2 | Correct | 72 ms | 4612 KB | Output is correct |
3 | Correct | 51 ms | 3776 KB | Output is correct |
4 | Correct | 74 ms | 4488 KB | Output is correct |