# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
529891 | Policarpo | Type Printer (IOI08_printer) | C++17 | 1100 ms | 197036 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) (10*(5e5 + 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 val[MAX];
char s[22];
vector<pair<int, char>> adj[MAX];
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;
adj[u].push_back(make_pair(trie[u][c], c));
}
val[trie[u][c]] = c+'a';
u = trie[u][c];
}
t[u] = 1;
}
int a(int u) {
int nivel = 0;
for (auto x : adj[u]) {
int v = x.first;
if (nivel < 1 + a(v)) {
nivel = 1 + a(v);
maxn[u] = v;
}
}
return nivel;
}
void b(int u) {
++resp;
if (t[u]) {
++tot;
++resp;
}
for (auto x : adj[u]) {
int v = x.first;
if (maxn[u] == v) continue;
b(v);
if (tot != n) {
++resp;
}
}
if (maxn[u]!=-1) {
b(maxn[u]);
if (tot != n) resp++;
}
}
void solve(int u) {
if (u) printf("%c\n", val[u]);
if (t[u]) {
printf("P\n");
++tot;
}
for (auto x : adj[u]) {
int v = x.first;
char c = x.second;
if (maxn[u] == v) continue;
solve(v);
if (tot != n) printf("-\n");
}
if (maxn[u]!=-1) {
solve(maxn[u]);
if (tot != n) printf("-\n");
}
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%s", s);
add(s);
}
memset(maxn, -1, sizeof maxn);
a(0);
b(0);
cout << --resp << endl;
tot = 0;
solve(0);
}
컴파일 시 표준 에러 (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... |