#include <bits/stdc++.h>
using namespace std;
string palabra[25002];
vector<char> res;
int main()
{
int n;
cin>>n;
string mayor,aux,aux2;
for(int i=0;i<n;i++){
cin>>palabra[i];
if(palabra[i].size()>mayor.size()) mayor=palabra[i];
}
sort(palabra,palabra+n);
int i=0,j=n-1,x,y,auxi,auxj;
int w,z,pos=0;
while(pos<mayor.size()){
x=i; y=j;
auxi=i; auxj=j;
while(x<=y){
z=(x+y)/2;
aux=palabra[z];
if(aux[pos]==mayor[pos]){
w=z;
y=z-1;
}
else if(aux[pos]<mayor[pos]) x=z+1;
else y=z-1;
}
x=i; y=j;
i=w;
while(x<=y){
z=(x+y)/2;
aux=palabra[z];
if(aux[pos]==mayor[pos]){
j=z;
x=z+1;
}
else if(aux[pos]<mayor[pos]) x=z+1;
else y=z-1;
}
for(z=auxi;z<i;z++){
if(z==auxi){
aux=palabra[z];
for(int k=pos;k<aux.size();k++){
res.push_back(aux[k]);
}
res.push_back('P');
}
else{
aux2=palabra[z];
int k=pos;
for(k;k<aux.size();k++){
if(aux2[k]!=aux[k]) break;
}
for(int l=k;l<aux.size();l++){
res.push_back('-');
}
for(k;k<aux2.size();k++){
res.push_back(aux2[k]);
}
res.push_back('P');
aux=aux2;
}
if(z==i-1){
for(int k=pos;k<aux.size();k++){
res.push_back('-');
}
}
}
for(z=j+1;z<=auxj;z++){
if(z==j+1){
aux=palabra[z];
for(int k=pos;k<aux.size();k++){
res.push_back(aux[k]);
}
res.push_back('P');
}
else{
aux2=palabra[z];
int k=pos;
for(k;k<aux.size();k++){
if(aux2[k]!=aux[k]) break;
}
for(int l=k;l<aux.size();l++){
res.push_back('-');
}
for(k;k<aux2.size();k++){
res.push_back(aux2[k]);
}
res.push_back('P');
aux=aux2;
}
if(z==auxj){
for(int k=pos;k<aux.size();k++){
res.push_back('-');
}
}
}
res.push_back(mayor[pos]);
if(palabra[i].size()==pos+1){
res.push_back('P');
i++;
}
pos++;
}
cout<<res.size()<<endl;
for(char l:res){
cout<<l<<endl;
}
return 0;
}
Compilation message
printer.cpp: In function 'int main()':
printer.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | while(pos<mayor.size()){
| ~~~^~~~~~~~~~~~~
printer.cpp:49:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for(int k=pos;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:57:21: warning: statement has no effect [-Wunused-value]
57 | for(k;k<aux.size();k++){
| ^
printer.cpp:57:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for(k;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:60:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int l=k;l<aux.size();l++){
| ~^~~~~~~~~~~
printer.cpp:63:21: warning: statement has no effect [-Wunused-value]
63 | for(k;k<aux2.size();k++){
| ^
printer.cpp:63:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(k;k<aux2.size();k++){
| ~^~~~~~~~~~~~
printer.cpp:70:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | for(int k=pos;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:78:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | for(int k=pos;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:86:21: warning: statement has no effect [-Wunused-value]
86 | for(k;k<aux.size();k++){
| ^
printer.cpp:86:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(k;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:89:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | for(int l=k;l<aux.size();l++){
| ~^~~~~~~~~~~
printer.cpp:92:21: warning: statement has no effect [-Wunused-value]
92 | for(k;k<aux2.size();k++){
| ^
printer.cpp:92:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
92 | for(k;k<aux2.size();k++){
| ~^~~~~~~~~~~~
printer.cpp:99:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | for(int k=pos;k<aux.size();k++){
| ~^~~~~~~~~~~
printer.cpp:105:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
105 | if(palabra[i].size()==pos+1){
| ~~~~~~~~~~~~~~~~~^~~~~~~
printer.cpp:46:21: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
46 | for(z=auxi;z<i;z++){
| ~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
2 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
972 KB |
Output is correct |
2 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
972 KB |
Output is correct |
2 |
Correct |
10 ms |
1112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
1140 KB |
Output is correct |
2 |
Correct |
22 ms |
1180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
1252 KB |
Output is correct |
2 |
Correct |
148 ms |
1776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
160 ms |
1560 KB |
Output is correct |
2 |
Correct |
50 ms |
1444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
2488 KB |
Output is correct |
2 |
Correct |
885 ms |
4876 KB |
Output is correct |
3 |
Correct |
506 ms |
3824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
2116 KB |
Output is correct |
2 |
Execution timed out |
1020 ms |
5668 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |