# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
927941 | TAhmed33 | Type Printer (IOI08_printer) | C++98 | 66 ms | 5484 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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';
}
컴파일 시 표준 에러 (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... |