# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74728 | goodbaton | Type Printer (IOI08_printer) | C++14 | 159 ms | 63772 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 <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;
}
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... |