| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 448040 | Alex_tz307 | Type Printer (IOI08_printer) | C++17 | 2 ms | 204 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
ifstream fin("text.in");
ofstream fout("text.out");
struct node {
int level;
bool is_end, is_marked;
node *son[26];
node() {
level = is_end = is_marked = 0;
for (int i = 0; i < 26; ++i)
son[i] = nullptr;
}
};
string s;
int longest;
bool found;
vector<char> sol;
void max_self(int &x, int y) {
x = max(x, y);
}
void Insert(node *nod, int p) {
max_self(longest, nod->level);
if (p == (int)s.size()) {
nod->is_end = true;
return;
}
int nxt = s[p] - 'a';
if (nod->son[nxt] == nullptr) {
nod->son[nxt] = new node;
nod->son[nxt]->level = nod->level + 1;
}
Insert(nod->son[nxt], p + 1);
}
bool mark(node *nod) {
bool is_leaf = true;
for (int i = 0; i < 26 && is_leaf; ++i)
if (nod->son[i] != nullptr)
is_leaf = false;
if (is_leaf) {
if (found)
return false;
if (nod->level == longest) {
nod->is_marked = true;
found = true;
return true;
}
return false;
}
bool ok = false;
for (int i = 0; i < 26 && !ok; ++i)
if (nod->son[i] != nullptr)
ok |= mark(nod->son[i]);
nod->is_marked = ok;
return ok;
}
void solve(node *nod) {
if (nod->is_end)
sol.emplace_back('P');
bool is_leaf = true;
for (int i = 0; i < 26; ++i) {
if (nod->son[i] != nullptr) {
is_leaf = false;
if (nod->son[i]->is_marked == false) {
sol.emplace_back('a' + i);
solve(nod->son[i]);
sol.emplace_back('-');
}
}
}
for (int i = 0; i < 26; ++i) {
if (nod->son[i] != nullptr && nod->son[i]->is_marked == true) {
sol.emplace_back('a' + i);
solve(nod->son[i]);
break;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n;
fin >> n;
node* root = new node;
for (int i = 0; i < n; ++i) {
fin >> s;
Insert(root, 0);
}
mark(root);
solve(root);
fout << sol.size() << '\n';
for (auto it : sol)
fout << it << '\n';
return 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... | ||||
