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>
#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... |