# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
261913 | evpipis | Type Printer (IOI08_printer) | C++11 | 185 ms | 99692 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;
#define pb push_back
vector<char> out;
struct node{
int wrd, dep;
node *kid[26];
node(){
wrd = dep = 0;
for (int i = 0; i < 26; i++)
kid[i] = NULL;
}
};
typedef node *pnode;
pnode root = new node();
void add(char str[]){
int m = strlen(str);
pnode cur = root;
for (int j = 0; j < m; j++){
cur->dep = max(cur->dep, m);
if (cur->kid[str[j]-'a'] == NULL)
cur->kid[str[j]-'a'] = new node();
cur = cur->kid[str[j]-'a'];
}
cur->dep = max(cur->dep, m);
cur->wrd = 1;
}
void dfs(pnode u, int keep){
if (u->wrd)
out.pb('P');
pnode big = NULL;
int pos;
for (int j = 0; j < 26; j++){
pnode v = u->kid[j];
if (v == NULL) continue;
if (big == NULL || v->dep > big->dep)
big = v, pos = j;
}
for (int j = 0; j < 26; j++){
pnode v = u->kid[j];
if (v == NULL || v == big)
continue;
out.pb(j+'a'), dfs(v, 0);
}
if (big != NULL)
out.pb(pos+'a'), dfs(big, keep);
if (!keep)
out.pb('-');
}
int main(){
int n;
char str[25];
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%s", str);
add(str);
}
dfs(root, 1);
printf("%d\n", (int)out.size());
for (int i = 0; i < out.size(); i++)
printf("%c\n", out[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... |