#include<bits/stdc++.h>
#define _for(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=5e5+5,M=31;
int A[N][M],num=0,maxn=0;
bool B[N];
string maxs;
void jr(string &s)
{
int l=s.size(),now=0;
_for(i,0,l-1)
{
char x=s[i];
if(!A[now][x-'a'])A[now][x-'a']=++num;
now=A[now][x-'a'];
}
B[now]=1;
}
void ss(int now,string &ans,int d,bool pd)
{
if(B[now])ans+='P';
char x=maxs[d];
_for(i,0,25)
{
if(pd&&i+'a'==x)continue;
if(A[now][i])
{
ans+=(char)(i+'a');
ss(A[now][i],ans,d+1,0);
ans+='-';
}
}
if(pd&&A[now][x-'a'])
{
ans+=x;
ss(A[now][x-'a'],ans,d+1,1);
ans+='-';
}
}
int main()
{
ios::sync_with_stdio(false),cin.tie(0);
int n;
cin>>n;
_for(i,1,n)
{
string x;
cin>>x;
if(x.size()>maxn)maxn=x.size(),maxs=x;
jr(x);
}
string ans="";
ss(0,ans,0,1);
int r=ans.size()-1;
while(ans[r]=='-')r--;
cout<<r+1<<endl;
_for(i,0,r)cout<<ans[i]<<endl;
return 0;
}
Compilation message
printer.cpp: In function 'int main()':
printer.cpp:49:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
49 | if(x.size()>maxn)maxn=x.size(),maxs=x;
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
1116 KB |
Output is correct |
2 |
Correct |
21 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
3696 KB |
Output is correct |
2 |
Correct |
124 ms |
7260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
159 ms |
8580 KB |
Output is correct |
2 |
Correct |
42 ms |
2136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
386 ms |
20996 KB |
Output is correct |
2 |
Correct |
863 ms |
47784 KB |
Output is correct |
3 |
Correct |
445 ms |
24664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
16448 KB |
Output is correct |
2 |
Correct |
1000 ms |
56888 KB |
Output is correct |
3 |
Correct |
513 ms |
27940 KB |
Output is correct |
4 |
Correct |
953 ms |
53664 KB |
Output is correct |