#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=30;
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';
return ;
}
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:53:14: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if(x.size()>maxn)maxn=x.size(),maxs=x;
| ~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3 ms |
1116 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3168 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
7772 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
19292 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
8 ms |
14940 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |