#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 |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
308 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
332 KB |
Output is correct |
2 |
Correct |
8 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
580 KB |
Output is correct |
2 |
Correct |
36 ms |
1036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
1236 KB |
Output is correct |
2 |
Correct |
76 ms |
1120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
120 ms |
2368 KB |
Output is correct |
2 |
Correct |
213 ms |
4684 KB |
Output is correct |
3 |
Correct |
192 ms |
3764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
2228 KB |
Output is correct |
2 |
Correct |
243 ms |
5580 KB |
Output is correct |
3 |
Correct |
226 ms |
4188 KB |
Output is correct |
4 |
Correct |
249 ms |
5384 KB |
Output is correct |