| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 643770 | ymm | Type Printer (IOI08_printer) | C++17 | 142 ms | 99636 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>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
struct node {
node *child[26];
char mx;
bool leaf;
} rt;
void add(string s)
{
node *t = &rt;
for (char c : s) {
c -= 'a';
if (!t->child[c])
t->child[c] = new node;
t = t->child[c];
}
t->leaf = 1;
}
vector<char> ans;
int dfs1(node *t, int h)
{
int mx = h;
Loop (i,0,26) {
if (t->child[i]) {
int x = dfs1(t->child[i], h+1);
if (x > mx) {
mx = x;
t->mx = i;
}
}
}
return mx;
}
void dfs2(node *t, bool ret)
{
if (t->leaf)
ans.push_back('P');
Loop (i,0,26) {
if ((ret || i != t->mx) && t->child[i]) {
ans.push_back(i+'a');
dfs2(t->child[i], 1);
ans.push_back('-');
}
}
if (!ret && t->child[t->mx]) {
ans.push_back(t->mx+'a');
dfs2(t->child[t->mx], 0);
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n;
cin >> n;
Loop (i,0,n) {
string s;
cin >> s;
add(s);
}
dfs1(&rt, 0);
dfs2(&rt, 0);
cout << ans.size() << '\n';
for (char c : ans)
cout << c << '\n';
}
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... | ||||
