# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927941 | 2024-02-15T14:25:35 Z | TAhmed33 | Type Printer (IOI08_printer) | C++ | 66 ms | 5484 KB |
#include <bits/stdc++.h> using namespace std; vector <string> arr; string ans; int main () { int n; cin >> n; arr.resize(n); string p; for (auto &i : arr) { cin >> i; if (i.length() > p.length()) { p = i; } } sort(arr.begin(), arr.end(), [p] (string &a, string &b) { int cnt1 = 0, cnt2 = 0; for (int i = 0; i < (int)a.length() && i < (int)p.length(); i++) { if (a[i] != p[i]) break; cnt1++; } for (int i = 0; i < (int)b.length() && i < (int)p.length(); i++) { if (b[i] != p[i]) break; cnt2++; } if (cnt1 == cnt2) return a < b; return cnt1 < cnt2; }); ans = arr[0]; ans += 'P'; for (int i = 1; i < n; i++) { if (arr[i - 1].length() > arr[i].length()) { int x = arr[i - 1].length() - arr[i].length(); for (int j = 0; j < x; j++) { arr[i - 1].pop_back(); ans += '-'; } string dd = arr[i]; while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } if (arr[i - 1].length() == arr[i].length()) { string dd = arr[i]; while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } string dd = arr[i]; while (arr[i].length() > arr[i - 1].length()) { arr[i].pop_back(); } while (!arr[i - 1].empty() && arr[i - 1] != arr[i]) { arr[i - 1].pop_back(); arr[i].pop_back(); ans += '-'; } for (int j = (int)arr[i - 1].length(); j < dd.length(); j++) { ans += dd[j]; } ans += 'P'; arr[i] = dd; continue; } cout << ans.length() << '\n'; for (auto i : ans) cout << i << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 428 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 444 KB | Output is correct |
2 | Correct | 2 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 568 KB | Output is correct |
2 | Correct | 10 ms | 1108 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 1140 KB | Output is correct |
2 | Correct | 10 ms | 1112 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 29 ms | 2548 KB | Output is correct |
2 | Correct | 52 ms | 4816 KB | Output is correct |
3 | Correct | 35 ms | 3772 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 26 ms | 2296 KB | Output is correct |
2 | Correct | 66 ms | 5484 KB | Output is correct |
3 | Correct | 40 ms | 4592 KB | Output is correct |
4 | Correct | 56 ms | 5328 KB | Output is correct |