| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 643770 | ymm | Type Printer (IOI08_printer) | C++17 | 142 ms | 99636 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
struct node {
node *child[26];
char mx;
bool leaf;
} rt;
void add(string s)
{
node *t = &rt;
for (char c : s) {
c -= 'a';
if (!t->child[c])
t->child[c] = new node;
t = t->child[c];
}
t->leaf = 1;
}
vector<char> ans;
int dfs1(node *t, int h)
{
int mx = h;
Loop (i,0,26) {
if (t->child[i]) {
int x = dfs1(t->child[i], h+1);
if (x > mx) {
mx = x;
t->mx = i;
}
}
}
return mx;
}
void dfs2(node *t, bool ret)
{
if (t->leaf)
ans.push_back('P');
Loop (i,0,26) {
if ((ret || i != t->mx) && t->child[i]) {
ans.push_back(i+'a');
dfs2(t->child[i], 1);
ans.push_back('-');
}
}
if (!ret && t->child[t->mx]) {
ans.push_back(t->mx+'a');
dfs2(t->child[t->mx], 0);
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int n;
cin >> n;
Loop (i,0,n) {
string s;
cin >> s;
add(s);
}
dfs1(&rt, 0);
dfs2(&rt, 0);
cout << ans.size() << '\n';
for (char c : ans)
cout << c << '\n';
}
컴파일 시 표준 에러 (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... | ||||
