#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 2e5 + 2;
const int mod = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n; cin >> n;
vector<string> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int mx = 0;
for (int i = 0; i < n; i++) if (a[i].size() > a[mx].size()) mx = i;
int sz = a[mx].size();
vector<int> id(n);
iota(id.begin(), id.end(), 0);
sort(id.begin(), id.end(), [&] (int i, int j) {
int x = a[i].size(); int y = a[j].size();
for (int p = 0; p < a[i].size(); p++) if (a[i][p] != a[mx][p]) {x = p; break;}
for (int p = 0; p < a[j].size(); p++) if (a[j][p] != a[mx][p]) {y = p; break;}
if (x != y) return x < y;
return a[i] < a[j];
});
vector<char> ans;
for (int i = 0; i < n; i++) {
if (i > 0) {
int w = min(a[id[i - 1]].size(), a[id[i]].size());
for (int j = 0; j < min(a[id[i - 1]].size(), a[id[i]].size()); j++) if (a[id[i - 1]][j] != a[id[i]][j]) {w = j; break;}
for (int j = 0; j < a[id[i - 1]].size() - w; j++) ans.push_back('-');
for (int j = w; j < a[id[i]].size(); j++) ans.push_back(a[id[i]][j]);
}
else for (int j = 0; j < a[id[i]].size(); j++) ans.push_back(a[id[i]][j]);
ans.push_back('P');
}
cout << ans.size() << en;
for (auto u : ans) cout << u << en;
return 0;
}
Compilation message
printer.cpp: In lambda function:
printer.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (int p = 0; p < a[i].size(); p++) if (a[i][p] != a[mx][p]) {x = p; break;}
| ~~^~~~~~~~~~~~~
printer.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int p = 0; p < a[j].size(); p++) if (a[j][p] != a[mx][p]) {y = p; break;}
| ~~^~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:34:31: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
34 | for (int j = 0; j < min(a[id[i - 1]].size(), a[id[i]].size()); j++) if (a[id[i - 1]][j] != a[id[i]][j]) {w = j; break;}
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:35:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j = 0; j < a[id[i - 1]].size() - w; j++) ans.push_back('-');
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:36:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for (int j = w; j < a[id[i]].size(); j++) ans.push_back(a[id[i]][j]);
| ~~^~~~~~~~~~~~~~~~~
printer.cpp:38:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | else for (int j = 0; j < a[id[i]].size(); j++) ans.push_back(a[id[i]][j]);
| ~~^~~~~~~~~~~~~~~~~
printer.cpp:20:9: warning: unused variable 'sz' [-Wunused-variable]
20 | int sz = a[mx].size();
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
2 |
Correct |
8 ms |
1108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
1224 KB |
Output is correct |
2 |
Correct |
7 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
2416 KB |
Output is correct |
2 |
Correct |
44 ms |
4816 KB |
Output is correct |
3 |
Correct |
28 ms |
3780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
2252 KB |
Output is correct |
2 |
Correct |
51 ms |
5696 KB |
Output is correct |
3 |
Correct |
32 ms |
4300 KB |
Output is correct |
4 |
Correct |
45 ms |
5440 KB |
Output is correct |