#include <bits/stdc++.h>
using namespace std;
const int sz=5e5+1;
int trie[sz][26];
int bitdi[sz];
int last=0,cnt=0;
vector<char> cvb;
int n;
void qur(string s){
int curr=0;
for(auto &i : s){
if(trie[curr][i - 'a'])curr = trie[curr][i - 'a'];
else curr = trie[curr][i - 'a'] = ++last;
}
bitdi[curr]++;
}
void dfs(int node){
if(bitdi[node]){
for(int i=0;i<bitdi[node];++i)cvb.push_back('p');
cnt += bitdi[node];
}
if(cnt == n)return;
for(int i=0;i<26;++i){
if(trie[node][i]){
cvb.push_back(char('a' + i));
dfs(trie[node][i]);
}
}
cvb.push_back('-');
}
int main(){
cin >> n;
string a;
for(int i=0;i<n;++i){
cin >> a;
qur(a);
}
dfs(0);
cout << cvb.size() << '\n';
for(auto &i : cvb)cout << i << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
1116 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
3164 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
7640 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
18636 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
14540 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |