#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;
| ~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
9 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
1116 KB |
Output is correct |
2 |
Correct |
20 ms |
1372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
3416 KB |
Output is correct |
2 |
Correct |
127 ms |
7092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
8420 KB |
Output is correct |
2 |
Correct |
45 ms |
1884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
20500 KB |
Output is correct |
2 |
Correct |
855 ms |
46308 KB |
Output is correct |
3 |
Correct |
440 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
305 ms |
15932 KB |
Output is correct |
2 |
Execution timed out |
1004 ms |
55312 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |