# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
667340 | marvinthang | Type Printer (IOI08_printer) | C++17 | 122 ms | 99532 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 REP(i, n) for (int i = 0, _n = (n); i < _n; ++i)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++i)
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
struct Node {
Node *child[26];
int terminal;
Node() {
REP(i, 26) child[i] = nullptr;
terminal = 0;
}
};
int N;
string maxS;
Node *root = new Node();
void addString(const string &s) {
Node *p = root;
FORE(it, s) {
if (p->child[*it - 'a'] == nullptr) p->child[*it - 'a'] = new Node();
p = p->child[*it - 'a'];
}
p->terminal++;
}
void init(void) {
cin >> N;
int sum = 0;
REP(i, N) {
string s; cin >> s;
sum += s.size();
if (maxS.size() < s.size()) maxS = s;
addString(s);
}
}
string res;
void dfs(Node *p, int depth, bool type) {
REP(i, p->terminal) res += 'P';
if (depth == maxS.size()) return;
if (type) {
REP(i, 26) if (p->child[i] != nullptr && i != maxS[depth] - 'a') {
res += char(i + 'a');
dfs(p->child[i], depth + 1, 0);
res += '-';
}
res += maxS[depth];
dfs(p->child[maxS[depth] - 'a'], depth + 1, 1);
} else {
REP(i, 26) if (p->child[i] != nullptr) {
res += char(i + 'a');
dfs(p->child[i], depth + 1, 0);
res += '-';
}
}
}
void process(void) {
dfs(root, 0, 1);
cout << res.size() << '\n';
for (char c: res) cout << c << '\n';
}
int main(void) {
ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr);
file("type-printer");
init();
process();
return (0^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... |