#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
using namespace std;
const int N = 5e5 + 5;
int trie[N][26];
int kraj[N];
int ind;
int n;
int cnt = 0;
vector<string> v;
int m;
string ss;
int c;
vector<int> kk;
void _insert(string s)
{
int node = 0;
for(int i = 0;i<len(s);i++)
{
int c = s[i] - 'a';
if(!trie[node][c]) trie[node][c] = ++ind;
node = trie[node][c];
}
kraj[node] = 1;
}
int u;
void search(string s)
{
int node = 0;
for(int i = 0;i<len(s);i++)
{
int c = s[i] - 'a';
kk.pb(trie[node][c]);
node = trie[node][c];
}
}
void print(int node, int p, int raz, int ind)
{
if(kraj[node])
{
cnt++;
cout<<"P"<<endl;
}
for(int i = 0;i<26;i++)
{
if(trie[node][i]&&(i!=p||raz))
{
cout<<char(i+'a')<<endl;
int r = raz;
if(!r)
if(i!=p)
r = 1;
if(ind<len(ss)-1)
p = ss[ind+1] - 'a';
else
p = 30;
print(trie[node][i], p, r, ind+1);
cout<<"-"<<endl;
}
}
}
int main()
{
ios
cin>>n;
for(int i = 0;i<n;i++)
{
string s;
cin>>s;
_insert(s);
if(len(s)>len(ss))
ss = s;
}
int le = len(ss);
ss.pb('#');
cout<<2*ind - le + n<<endl;
search(ss);
print(0, ss[0]-'a', 0, 0);
for(int i = 0;i<le;i++)
{
cout<<ss[i]<<endl;
print(kk[i], ss[i+1]-'a', 0, i);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
492 KB |
Expected EOF |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
1132 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
3052 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
7660 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
49 ms |
18156 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
14316 KB |
printed invalid word |
2 |
Halted |
0 ms |
0 KB |
- |