# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
120075 | Boxworld | Type Printer (IOI08_printer) | C++14 | 122 ms | 49656 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 N=500500;
struct TREE{int nxt[26];bool end,mk;}tree[N];
string s,m;
char ss[N],ans[N*2+1];
int S=0,T=0,n,root=0,fin=0;
int newnode(){
T++;
memset(tree[T].nxt,-1,sizeof(tree[T].nxt));
return T;
}
void insert(string x){
int cnr=root;
for (int i=0;i<x.length();i++){
int now=x[i]-'a';
if (tree[cnr].nxt[now]==-1)tree[cnr].nxt[now]=newnode();
cnr=tree[cnr].nxt[now];
}
tree[cnr].end=1;
}
void mark(string x){
int cnr=root;
for (int i=0;i<x.length();i++){
int now=x[i]-'a';
cnr=tree[cnr].nxt[now];
tree[cnr].mk=1;
}
}
void dfs(int cnr){
if(tree[cnr].end==1)ans[S++]='P';
int tmp=-1;
for (int i=0;i<26;i++)
if (tree[cnr].nxt[i]!=-1){
int now=tree[cnr].nxt[i];
if (tree[now].mk!=1){
ans[S++]=char(i+'a');
dfs(now);
}
else tmp=i;
}
if (tmp!=-1){
ans[S++]=char(tmp+'a');
dfs(tree[cnr].nxt[tmp]);
}
if (tmp==-1&&tree[cnr].mk)fin=1;
if(!fin)ans[S++]='-';
}
int main(){
scanf("%d",&n);
memset(tree[0].nxt,-1,sizeof(tree[0].nxt));
for (int i=0;i<n;i++){
scanf("%s",ss);
string s(ss);
insert(s);
if(s.length()>m.length())m=s;
}
mark(m);
dfs(root);
printf("%d\n",S);
for (int i=0;i<S;i++)printf("%c\n",ans[i]);
return 0;
}
Compilation message (stderr)
# | 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... |