This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |