# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
440476 | dxz05 | Type Printer (IOI08_printer) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 3e2;
string str[MAXN];
int main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n;
int ind = 0;
for (int i = 1; i <= n; i++){
cin >> str[i];
if (str[i].size() > str[ind].size()) ind = i;
}
string longest = str[ind];
for (int i = 1; i <= n; i++){
int j = 0;
while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++;
str[i] = string(j, '{') + str[i];
}
sort(str + 1, str + n + 1);
vector<char> ans;
for (int it = 1; it <= n; it++){
int j = 0;
while (j < str[it].size() && str[it][j] == '{') j++; else
break;
str[it].erase(0, j);
string s = str[it], t = str[it - 1];
while (t.size() > s.size()){
ans.push_back('-');
t.pop_back();
}
int cnt = 0;
for (int i = 0; i < t.size(); i++){
if (i < s.size() && t[i] == s[i]) cnt++; else
break;
}
while (t.size() > cnt){
t.pop_back();
ans.push_back('-');
}
for (int i = cnt; i < s.size(); i++){
ans.push_back(s[i]);
}
ans.push_back('P');
}
cout << ans.size() << endl;
for (char c : ans) cout << c << endl;
return 0;
}