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;
struct yas{
string s;
};
bool operator<(yas &a,yas &b){
if(a.s.size() == b.s.size())return a.s < b.s;
return a.s.size() < b.s.size();
};
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<yas> sira(n);
for(auto &i : sira){
cin >> i.s;
}
sort(sira.begin(),sira.end());
// reverse(sira.begin(),sira.end());
for(auto &i : sira)qur(i.s);
dfs(0);
while(cvb[cvb.size() - 1] == '-')cvb.pop_back();
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... |