# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
120075 | Boxworld | Type Printer (IOI08_printer) | C++14 | 122 ms | 49656 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (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... |