# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
445769 | 2021-07-19T14:10:35 Z | dxz05 | Type Printer (IOI08_printer) | C++14 | 105 ms | 43712 KB |
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define SZ(x) (int)(x).size() const int MAXN = 1e6 + 3e2; pair<int, string> str[MAXN]; int main(){ //ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr); int n; scanf("%d", &n); int ind = 0; for (int i = 1; i <= n; i++){ char c[25]; scanf("%s", &c); int len = strlen(c); str[i].second.resize(len); for (int j = 0; j < len; j++) str[i].second[j] = c[j]; if (str[i].second.size() > str[ind].second.size()) ind = i; } string longest = str[ind].second; for (int i = 1; i <= n; i++){ int j = 0; while (j < str[i].second.size() && str[i].second[j] == longest[j]) j++; str[i].first = j; } sort(str + 1, str + n + 1); vector<char> ans; for (int it = 1; it <= n; it++){ string s = str[it].second, t = str[it - 1].second; if (SZ(t) > SZ(s)){ int need = SZ(t) - SZ(s); while (need--) ans.push_back('-'); t.resize(s.size()); } int cnt = 0; for (int i = 0; i < min(SZ(t), SZ(s)); i++){ if (t[i] == s[i]) cnt++; else break; } int need = max(0, SZ(t) - cnt); while (need--){ ans.push_back('-'); } for (int i = cnt; i < s.size(); i++){ ans.push_back(s[i]); } ans.push_back('P'); } printf("%d\n", SZ(ans)); for (char c : ans) printf("%c\n", c); return 0; } /** 3 print the poem */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 39372 KB | Output is correct |
2 | Correct | 25 ms | 39372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 39452 KB | Output is correct |
2 | Correct | 26 ms | 39444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 39372 KB | Output is correct |
2 | Correct | 23 ms | 39372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 39364 KB | Output is correct |
2 | Correct | 24 ms | 39444 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 39352 KB | Output is correct |
2 | Correct | 24 ms | 39448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 25 ms | 39508 KB | Output is correct |
2 | Correct | 25 ms | 39544 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 39672 KB | Output is correct |
2 | Correct | 33 ms | 39940 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 37 ms | 39996 KB | Output is correct |
2 | Correct | 34 ms | 39756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 40744 KB | Output is correct |
2 | Correct | 89 ms | 42808 KB | Output is correct |
3 | Correct | 65 ms | 42176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 40280 KB | Output is correct |
2 | Correct | 105 ms | 43456 KB | Output is correct |
3 | Correct | 71 ms | 42568 KB | Output is correct |
4 | Correct | 99 ms | 43712 KB | Output is correct |