# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
855097 | vjudge1 | Type Printer (IOI08_printer) | C++14 | 0 ms | 0 KiB |
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 sig=26,nn=25000;
struct node{
int ch[sig];
bool mark,end;
}t[nn*20];
int sz=0;
void insert(const string& s){
int u=0;
for(char c:s){
int d=c-'a',&cu=t[u].ch[d];
if(!cu) cu+=sz;
u=cu;
}
t[u].end=true;
}
void dfs(int u,string& ans){
const node& x=t[u];
if(x.end) ans+='p';
int mi=-1;
for(in i=0;i<sig;i++){
int v=x.ch[i]
if(!v) continue;
if(t[v].mark)
mi=i;
else
ans+=i+'a',dfs(v,ans);
}
if(mi=-1)
ans+=mi+'a',dfs(x.ch[i],ans);
ans+='-';
}
int main(){
int n;
cin>>n;
string s,l;
for(int i0=;i<n;i++){
cin>>s,insert(s);
if(s.length()>l.length()) l=s;
}
for(size_t i=0,u=0;i<l.size();i++)
u=t[u].ch[l[i]-'a'],t[u].mark=true;
s.clear(),dfs(0,s);
while(s.back=='-') s.pop_back();
cout<<s.size()<<'\n';
for(char c:s) cout<<c<<"\n";
return 0;
}