# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
927941 | TAhmed33 | Type Printer (IOI08_printer) | C++98 | 66 ms | 5484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |