# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
226664 | tushar_2658 | Type Printer (IOI08_printer) | C++14 | 163 ms | 51692 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;
const int maxn = 1000000;
char s[25];
int t[maxn][26], ed[maxn], cnt[maxn];
int node = 0;
int par[maxn];
void insert(){
int cur = 0;
int sz = strlen(s);
for(int i = 0; i < sz; ++i){
int idx = s[i] - 'a';
if(t[cur][idx] == 0){
t[cur][idx] = ++node;
}
cur = t[cur][idx];
}
ed[cur] = 1;
}
vector<char> v;
void get(int cur){
cnt[cur] = 1;
for(int i = 0; i < 26; ++i){
if(t[cur][i]){
get(t[cur][i]);
cnt[cur] = max(cnt[cur], cnt[t[cur][i]] + 1);
}
}
}
void dfs(int cur){
if(ed[cur]){
ed[cur] = 0;
v.push_back('P');
}
vector<pair<int, int>> vv;
int sz = 0;
for(int i = 0; i < 26; ++i){
if(t[cur][i]){
vv.push_back(make_pair(cnt[t[cur][i]], i));
sz++;
}
}
sort(vv.begin(), vv.end());
for(int i = 0; i < sz; ++i){
v.push_back((char)(vv[i].second + 'a'));
dfs(t[cur][vv[i].second]);
v.push_back('-');
}
}
int main(int argc, char const *argv[])
{
// freopen("in.txt", "r", stdin);
int n;
cin >> n;
for(int i = 0; i < n; ++i){
scanf("%s", s);
insert();
}
get(0);
dfs(0);
int sz = v.size();
while(v[sz - 1] == '-')--sz;
printf("%d\n", sz);
for(int i = 0; i < sz; ++i){
printf("%c\n", v[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... |