| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 636143 | tvladm2009 | Type Printer (IOI08_printer) | C++14 | 214 ms | 105488 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
const int SIGMA = 26;
struct Trie {
Trie *sons[SIGMA];
int freq;
int words;
bool is_ancestor;
Trie() {
freq = 0;
words = 0;
is_ancestor = false;
for (int i = 0; i < SIGMA; i++) {
sons[i] = NULL;
}
}
};
void ins(Trie *&root, string s, int pos = 0) {
if (pos == s.size()) {
root->words++;
} else {
if (root->sons[s[pos] - 'a'] == NULL) {
root->sons[s[pos] - 'a'] = new Trie();
}
ins(root->sons[s[pos] - 'a'], s, pos + 1);
}
}
int n, answer = 0;
void stramosi(Trie *&root, string s, int pos = 0) {
if (pos != s.size()) {
root->sons[s[pos] - 'a']->is_ancestor = true;
stramosi(root->sons[s[pos] - 'a'], s, pos + 1);
}
}
void solve(Trie *&root) {
answer += root->words;
for (int i = 0; i < SIGMA; i++) {
if (root->sons[i] != NULL && root->sons[i]->is_ancestor == false) {
answer++;
solve(root->sons[i]);
answer++;
}
}
for (int i = 0; i < SIGMA; i++) {
if (root->sons[i] != NULL && root->sons[i]->is_ancestor == true) {
answer++;
solve(root->sons[i]);
}
}
}
void dfs(Trie *&root) {
for (int i = 1; i <= root->words; i++) {
cout << "P\n";
}
for (int i = 0; i < SIGMA; i++) {
if (root->sons[i] != NULL && root->sons[i]->is_ancestor == false) {
cout << char(i + 'a') << "\n";
dfs(root->sons[i]);
cout << "-\n";
}
}
for (int i = 0; i < SIGMA; i++) {
if (root->sons[i] != NULL && root->sons[i]->is_ancestor == true) {
cout << char(i + 'a') << "\n";
dfs(root->sons[i]);
}
}
}
int main() {
cin >> n;
Trie *root = new Trie();
string tmp = "";
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
if (s.size() > tmp.size()) {
tmp = s;
}
ins(root, s);
}
stramosi(root, tmp);
solve(root);
cout << answer << "\n";
dfs(root);
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... | ||||
