#include <bits/stdc++.h>
using namespace std;
int n;
const int sz=5e5 + 1;
int trie[sz][26];
int bitis[sz];
vector<int> gt[sz];
vector<char> cvb;
int last=0;
void qur(string s){
int curr=0;
for(auto &i : s){
if(trie[curr][i-'a'])curr = trie[curr][i - 'a'];
else{
gt[curr].push_back(i - 'a');
curr = trie[curr][i - 'a'] = ++last;
}
}
bitis[curr]++;
}
void dfs(int node){
if(bitis[node]){
for(int i=0;i<bitis[node];++i)cvb.push_back('P');
}
for(auto &i : gt[node]){
cvb.push_back(i + 'a');
dfs(trie[node][i]);
}
cvb.push_back('-');
}
int main(){
cin >> n;
vector<string> sira(n);
for(auto &i : sira){
cin >> i;
}
sort(sira.begin(),sira.end());
reverse(sira.begin(),sira.end());
for(auto &i : sira)qur(i);
dfs(0);
while(cvb.back() == '-')cvb.pop_back();
cout << cvb.size() << '\n';
for(auto &i : cvb)cout << i << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
12120 KB |
Output is correct |
2 |
Correct |
5 ms |
12124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
12124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
13148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
15656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
22 ms |
21460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
35540 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
30412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |