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;
using ll = long long;
int node_num=0,pcount=0;
vector<vector<int>> trie(1000,vector<int>(26,0));
vector<bool> stop(100000,false);
vector<char> ans;
void insert(string word){
int node=0;
for(char c:word){
if(trie[node][c-'a']==0){trie[node][c-'a']=++node_num;pcount++;}
node=trie[node][c-'a'];
}
stop[node]=true;
}
string s="";
void dfs(int u){
int node=u;
if(stop[node]==true){ans.push_back('P');}
for(int i=0;i<26;i++){
if(trie[node][i]==0){continue;}
ans.push_back(char('a'+i));
pcount--;
int v=trie[node][i];
dfs(v);
if(pcount==0){return;}
ans.push_back('-');
}
}
void solve(){
ll n;cin>>n;
for(int i=0;i<n;i++){
string s;cin>>s;
insert(s);
}
dfs(0);
cout<<ans.size()<<endl;
for(auto x:ans){cout<<x<<endl;}
}
int main(){
solve();
}
# | 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... |