이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x.size())
using namespace std;
int commonPrefix(string& x, string& y) {
for (int i = 0; i < min(sz(x), sz(y)); ++i){
if (x[i] != y[i]) return i;
}
return min(sz(x), sz(y));
}
void solve() {
vector<char> ans;
int n, ml = 0, lcp;
cin >> n;
int l = 0, r = n-1;
string s[n], ms, last = "";
for (int i = 0; i < n; ++i) {
cin >> s[i];
if (sz(s[i]) > ml) {
ms = s[i];
ml = sz(s[i]);
}
}
sort(s, s+n);
for (int i = 0; i <= ml; ++i) {
while (commonPrefix(s[l], ms) == i) {
lcp = commonPrefix(last, s[l]);
for (int j = 0; j < (sz(last)-lcp); ++j) {
// cout << "-\n";
ans.push_back('-');
}
for (int j = lcp; j < sz(s[l]); ++j) {
// cout << s[l][j] << "\n";
ans.push_back(s[l][j]);
}
// cout << "P\n";
ans.push_back('P');
last = s[l];
++l;
}
while (commonPrefix(s[r], ms) == i) {
lcp = commonPrefix(last, s[r]);
for (int j = 0; j < (sz(last)-lcp); ++j) {
// cout << "-\n";
ans.push_back('-');
}
for (int j = lcp; j < sz(s[r]); ++j) {
// cout << s[r][j] << "\n";
ans.push_back(s[r][j]);
}
// cout << "P\n";
ans.push_back('P');
last = s[r];
--r;
}
}
cout << (sz(ans)-1) << "\n";
for (int i = 0; i < (sz(ans)-1); ++i) {
cout << ans[i] << "\n";
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | 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... |