#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';
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 |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1116 KB |
Output is correct |
2 |
Correct |
27 ms |
1372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
70 ms |
3416 KB |
Output is correct |
2 |
Correct |
124 ms |
7252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
156 ms |
8476 KB |
Output is correct |
2 |
Correct |
42 ms |
2116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
377 ms |
20372 KB |
Output is correct |
2 |
Correct |
849 ms |
46564 KB |
Output is correct |
3 |
Correct |
470 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
306 ms |
15996 KB |
Output is correct |
2 |
Execution timed out |
1052 ms |
55228 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |