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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> s(n);
string t;
for (int i = 0; i < n; i++) {
cin >> s[i];
if (t.size() < s[i].size()) {
t = s[i];
}
}
vector<vector<int>> a(t.size(), vector<int>(26));
for (int i = 0; i < (int) t.size(); i++) {
iota(a[i].begin(), a[i].end(), 0);
a[i][t[i] - 'a'] = 100;
}
sort(s.begin(), s.end(), [&](string xx, string yy) {
vector<int> x;
for (int i = 0; i < (int) xx.size(); i++) {
x.emplace_back(a[i][xx[i] - 'a']);
}
vector<int> y;
for (int i = 0; i < (int) yy.size(); i++) {
y.emplace_back(a[i][yy[i] - 'a']);
}
return x < y;
});
string ans;
t = "";
for (int i = 0; i < n; i++) {
while (!t.empty() && s[i].find(t) != 0) {
ans.push_back('-');
t.pop_back();
}
while (s[i] != t) {
ans.push_back(s[i][t.size()]);
t.push_back(s[i][t.size()]);
}
ans.push_back('P');
}
cout << ans.size() << '\n';
for (char c : ans) {
cout << c << '\n';
}
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... |