| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1365287 | waygonz | Type Printer (IOI08_printer) | C++20 | 62 ms | 38648 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<char> ans;
struct Node {
char c;
int dep, dp = 1;
bool en = false;
vector<Node*> ch;
};
Node root;
void dfs(Node* u) {
for (auto &v : u->ch) {
dfs(v);
u->dp = max(u->dp, v->dp + 1);
}
}
void in(Node* u, bool hv) {
if (u != &root) ans.emplace_back(u->c);
if (u->en) ans.emplace_back('P');
if (!hv) {
for (auto &v : u->ch) in(v, false);
ans.emplace_back('-');
return;
}
if (u->ch.empty()) { return; }
int m = u->ch.size(), ans = -1;
for (int i = 0; i < m; i++) {
if (u->ch[i]->dp + 1 == u->dp && ans == -1) { ans = i; continue; }
in(u->ch[i], false);
}
in(u->ch[ans], true);
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n; cin >> n;
vector<string> a(n);
for (auto &x : a) cin >> x;
Node* ptr;
for (auto &x : a) {
ptr = &root;
for (auto &ch : x) {
bool found = false;
for (auto &c : ptr->ch) {
if (c->c == ch) ptr = c, found = true;
}
if (!found) {
Node* child = new Node;
child->c = ch;
child->dep = ptr->dep;
ptr->ch.emplace_back(child);
ptr = child;
}
}
ptr->en = true;
}
ptr = &root;
dfs(ptr);
in(ptr, true);
cout << ans.size() << '\n';
for (auto &c : ans) cout << c << '\n';
}| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
