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 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 (stderr)
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 |
---|
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... |