# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
131889 | dragonslayerit | Type Printer (IOI08_printer) | C++14 | 207 ms | 51676 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
struct Node{
int chd[26];
int has;
int depth;
}nodes[500005];
int nodes_cnt=1;
char str[64];
int longest=0;
int getchild(int node,int c){
int& ret=nodes[node].chd[c];
if(!ret){
ret=nodes_cnt++;
}
return ret;
}
void add(){
int curr=0;
for(int i=0;str[i];i++){
curr=getchild(curr,str[i]-'a');
}
nodes[curr].has=true;
}
std::string ans;
void dfs(int node){
for(int c=0;c<26;c++){
int child=nodes[node].chd[c];
if(child){
dfs(child);
nodes[node].depth=std::max(nodes[node].depth,nodes[child].depth+1);
}
}
}
void output(int node){
if(nodes[node].has) ans+='P';
int deep=-1;
for(int c=0;c<26;c++){
if(nodes[node].chd[c]){
if(deep==-1||nodes[nodes[node].chd[c]].depth>nodes[nodes[node].chd[deep]].depth){
deep=c;
}
}
}
for(int c=0;c<26;c++){
if(nodes[node].chd[c]&&c!=deep){
ans+='a'+c;
output(nodes[node].chd[c]);
ans+='-';
}
}
for(int c=0;c<26;c++){
if(nodes[node].chd[c]&&c==deep){
ans+='a'+c;
output(nodes[node].chd[c]);
ans+='-';
}
}
}
int main(){
int N;
scanf("%d",&N);
for(int i=0;i<N;i++){
scanf("%s",str);
add();
longest=std::max<int>(longest,strlen(str));
}
int len=nodes_cnt*2-2-longest+N;
dfs(0);
output(0);
ans.resize(len);
printf("%d\n",len);
for(char c:ans){
printf("%c\n",c);
}
}
컴파일 시 표준 에러 (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... |