#include<bits/stdc++.h>
/*
@@@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@ @@@@@@ @@@@@@@
@@@@@@@@@@@ @@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ @@@@@@@@
@@! @@! @@! @@! @@! @@@ @@! @@@ @@! @@@ @@! @@@
!@! !@! !@! !@! !@! @!@ !@! @!@ !@! @!@ !@! @!@
@!! !!@ @!@ @!!!:! @!@!@!@! @!@!!@! @!@!@!@! @!@ !@!
!@! ! !@! !!!!!: !!!@!!!! !!@!@! !!!@!!!! !@! !!!
!!: !!: !!: !!: !!! !!: :!! !!: !!! !!: !!!
:!: :!: :!: :!: !:! :!: !:! :!: !:! :!: !:!
::: :: :: :::: :: ::: :: ::: :: ::: :::: ::
: : : :: :: : : : : : : : : : :: : :
*/
using namespace std;
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define all(v) v.begin(),v.end()
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define sz(x) int(x.size())
#define mp make_pair
#define pb push_back
#define S second
#define F first
#define pss ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define jame(a,b) a=(a+b)%mod
#define taf(a,b) a=(a+2*mod-b)%mod
typedef long long ll;
typedef double dbl;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,pair<int,int>> piii;
typedef pair<int,long long> pil;
typedef pair<long long,int> pli;
const long long xn =1e6+5,mod=1e9+7;
map<char,int> ti[xn];
int cnt=1,n;
string s,ans;
void add(){
int cur=1;
f(i,0,sz(s)){
if(!ti[cur][s[i]])ti[cur][s[i]]=++cnt;
cur=ti[cur][s[i]];
}
}
void dfs(int v,int h,bool mark){
if(sz(ti[v])==0){
cout<<"P\n";
return;
}
for(pair<char,int> x:ti[v]){
if(mark && x.F==ans[h])continue;
cout<<x.F<<'\n';
dfs(x.S,h+1,0);
cout<<'-'<<'\n';
}
if(!mark)return;
cout<<ans[h]<<'\n';
dfs(ti[v][ans[h]],h+1,1);
}
int main(){
pss
cin>>n;
f(i,0,n){
cin>>s;
if(sz(s)>sz(ans))ans=s;
add();
}
cout<<(cnt-1)*2-sz(ans)+n<<'\n';
dfs(1,0,1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
47192 KB |
Output is correct |
2 |
Correct |
14 ms |
47196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
47196 KB |
Output is correct |
2 |
Correct |
13 ms |
47196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
47192 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
47192 KB |
Output is correct |
2 |
Incorrect |
13 ms |
47196 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
47452 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
47708 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
48476 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
50656 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
46 ms |
55476 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
53584 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |