# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
369411 | NachoLibre | Type Printer (IOI08_printer) | C++17 | 177 ms | 98704 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 sz(a) ((int)a.size())
using namespace std;
struct cac {
cac *a[26];
int l;
bool p;
cac() : p(0), l(26) {
for(int i = 0; i < 26; ++i) a[i] = NULL;
}
} *rt = new cac();
int n, w;
string s, l;
void G(cac *x) {
for(int i = 0; i < 26; ++i) {
if(i != x->l && x->a[i] != NULL) {
cout << (char)('a' + i) << "\n";
if(x->a[i]->p) cout << "P\n";
G(x->a[i]);
cout << "-\n";
}
}
if(x->l != 26) {
cout << (char)('a' + x->l) << "\n";
if(x->a[x->l]->p) cout << "P\n";
G(x->a[x->l]);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for(int i = 0; i < n; ++i) {
cin >> s;
if(sz(s) > sz(l)) l = s;
cac *dg = rt;
for(int j = 0; j < sz(s); ++j) {
if(dg->a[s[j] - 'a'] == NULL) {
w += 2;
dg->a[s[j] - 'a'] = new cac();
}
dg = dg->a[s[j] - 'a'];
}
dg->p = 1;
}
{
cac *dg = rt;
for(int i = 0; i < sz(l); ++i) {
dg->l = l[i] - 'a';
dg = dg->a[dg->l];
}
}
cout << w - sz(l) + n << "\n";
G(rt);
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... |