# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529888 | Policarpo | Type Printer (IOI08_printer) | C++17 | 1089 ms | 21836 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 <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <set>
#include <stack>
#include <bitset>
#define ll long long
#define INF (1e9)
#define MAX (int) (1e5 + 5)
#define MOD 1000000007
#define par pair<int, int>
#define all(v) v.begin(), v.end()
#define sz(x) (int) ((x).size())
#define esq(x) (x<<1)
#define dir(x) ((x<<1)|1)
#define lsb(x) (x & -x)
#define W(x) cout << #x << ": " << x << endl
#define Wii(x) cout << x.first << ' ' << x.second << endl
using namespace std;
int n, t[MAX], trie[MAX][26], qnt, tot, resp, maxn[MAX];
char s[22];
void add(char s[]) {
int u = 0, ts = strlen(s);
for (int i = 0; i < ts; i++) {
char c = s[i] - 'a';
if (!trie[u][c]) trie[u][c] = ++qnt;
u = trie[u][c];
}
t[u] = 1;
}
int a(int u) {
int nivel = 0;
for (int i = 0; i < 26; i++) {
if (!trie[u][i]) continue;
if (nivel < 1 + a(trie[u][i])) {
nivel = 1 + a(trie[u][i]);
maxn[u] = i;
}
}
return nivel;
}
void b(int u) {
++resp;
if (t[u]) {
++tot;
++resp;
}
for (int i = 0; i < 26; i++) {
if (!trie[u][i] || maxn[u] == i) continue;
b(trie[u][i]);
if (tot != n) {
++resp;
}
}
if (trie[u][maxn[u]]) {
b(trie[u][maxn[u]]);
if (tot != n) resp++;
}
}
void solve(int u, char c) {
if (u) printf("%c\n", c);
if (t[u]) {
printf("P\n");
++tot;
}
for (int i = 0; i < 26; i++) {
if (!trie[u][i] || maxn[u] == i) continue;
solve(trie[u][i], i + 'a');
if (tot != n) printf("-\n");
}
if (trie[u][maxn[u]]) {
solve(trie[u][maxn[u]], maxn[u] + 'a');
if (tot != n) printf("-\n");
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
add(s);
}
a(0);
b(0);
cout << --resp << endl;
tot = 0;
solve(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... |