#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
vector<string> arr(N);
for(string &i : arr)cin >> i;
sort(arr.begin(), arr.end(), [](string a, string b){return a.size() < b.size();});
string bzz = arr.back();
sort(arr.begin(), arr.end(), [&](string a, string b){
int i = 0, j = 0;
for(; i < a.size(); i ++){if(a[i] != bzz[i]){i--;break;}}
for(; j < b.size(); j ++){if(b[j] != bzz[j]){j--;break;}}
if(i != j)
return i < j;
return a < b;
});
arr.push_back("");
vector<char> brr;
vector<string> ans;
string temp = "P";
for(string i : arr){
int k = 0;
while(k < brr.size() && k < i.size() && brr[k] == i[k]){
k++;
}
int t = brr.size();
for(int j = k; j < t; j ++){
temp += "-";
brr.pop_back();
}
if(k == 0){
ans.push_back(temp);
temp = "";
}
for(int j = k; j < i.size(); j ++){
brr.push_back(i[j]);
temp += i.substr(j, 1);
}
temp += "P";
}
ans.erase(ans.begin());
map<string, int> len;
for(string i : ans){
int t = count(i.begin(), i.begin() + i.rfind('P'), '-');
int tt = count(i.begin(), i.end(), 'P');
int ttt = i.rfind('P') - 2 * t - tt + 1;
len[i] = ttt;
}
sort(ans.begin(), ans.end(), [&](string a, string b){return len[a] < len[b];});
vector<char> a2;
for(string i : ans){
for(char j : i){
a2.push_back(j);
}
}
while(a2.back() =='-')a2.pop_back();
cout << a2.size() << endl;
for(char i : a2){
cout << i << endl;
}
return 0;
}
Compilation message
printer.cpp: In lambda function:
printer.cpp:17:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(; i < a.size(); i ++){if(a[i] != bzz[i]){i--;break;}}
| ~~^~~~~~~~~~
printer.cpp:18:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | for(; j < b.size(); j ++){if(b[j] != bzz[j]){j--;break;}}
| ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while(k < brr.size() && k < i.size() && brr[k] == i[k]){
| ~~^~~~~~~~~~~~
printer.cpp:29:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while(k < brr.size() && k < i.size() && brr[k] == i[k]){
| ~~^~~~~~~~~~
printer.cpp:41:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int j = k; j < i.size(); j ++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
1304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
1568 KB |
Output is correct |
2 |
Correct |
15 ms |
1128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
50 ms |
3352 KB |
Output is correct |
2 |
Correct |
69 ms |
6820 KB |
Output is correct |
3 |
Correct |
54 ms |
4564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
2992 KB |
Output is correct |
2 |
Correct |
79 ms |
7836 KB |
Output is correct |
3 |
Correct |
61 ms |
5084 KB |
Output is correct |
4 |
Correct |
78 ms |
7532 KB |
Output is correct |