# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
74728 | goodbaton | Type Printer (IOI08_printer) | C++14 | 159 ms | 63772 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cstring>
using namespace std;
typedef long long ll;
#define SIZE 25010
struct NODE{
int child[26];
int max;
bool fin;
NODE(){
for(int i=0;i<26;i++) child[i] = -1;
max = 0;
fin = false;
}
};
NODE node[SIZE*21];
int node_size = 1;
char ans[SIZE*42];
int ans_size = 0;
int add(char *s,int now=0,int depth=0){
if(s[depth]=='\0'){
node[now].max = max(node[now].max,depth);
node[now].fin = true;
return node[now].max;
}
int next_c = s[depth]-'a';
if(node[now].child[next_c]==-1){
node[now].child[next_c] = node_size;
node_size++;
}
node[now].max = max(node[now].max, add(s,node[now].child[next_c],depth+1) );
return node[now].max;
}
bool fin = false;
int counter = 0;
void solve(int now=0){
if(node[now].fin) ans[ans_size++] = 'P';
counter++;
for(int i=0;i<26;i++){
if(node[now].child[i]==-1) continue;
int to = node[now].child[i];
if(node[now].max != node[to].max){
ans[ans_size++] = 'a'+i;
solve(to);
}
}
for(int i=0;i<26;i++){
if(node[now].child[i]==-1) continue;
int to = node[now].child[i];
if(node[now].max == node[to].max){
ans[ans_size++] = 'a'+i;
solve(to);
}
}
if(counter!=node_size) ans[ans_size++] = '-';
}
int main(){
int n;
char word[25];
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%s",word);
add(word);
}
solve();
printf("%d\n",ans_size);
for(int i=0;i<ans_size;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... |