| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 716345 | kartapolov | Type Printer (IOI08_printer) | C++14 | 1078 ms | 119988 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
struct vertex {
bool term = 0;
vector<vertex*> children = vector<vertex*>(26, nullptr);
vertex() = default;
void add(const string& s, int i = 0) {
if (this->children[s[i] - 'a'] == nullptr) {
this->children[s[i] - 'a'] = new vertex();
}
if (i + 1 == s.size()) {
(this->children[s[i] - 'a']->term) = true;
} else {
this->children[s[i] - 'a']->add(s, i + 1);
}
}
};
vector<char> ans;
string maxw = "";
int n, k;
void dfs(vertex* v, int h = 0) {
if (v->term) {
ans.push_back('P');
++k;
}
for (int i = 0; i < 26; ++i) {
if (!(h < maxw.size() and i == maxw[h] - 'a') and (v->children[i] != nullptr)) {
ans.push_back(i + 'a');
dfs(v->children[i], h + 1);
if (k != n) ans.push_back('-');
}
}
if (h < maxw.size() and v->children[maxw[h] - 'a'] != nullptr) {
ans.push_back(maxw[h]);
dfs(v->children[maxw[h] - 'a'], h + 1);
if (k != n) ans.push_back('-');
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
vertex root;
for (int i = 0; i < n; ++i) {
string word;
cin >> word;
if (word.size() > maxw.size()) maxw = word;
root.add(word);
}
k = 0;
dfs(&root);
cout << ans.size() << endl;
for (char c : ans) cout << c << endl;
}
컴파일 시 표준 에러 (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... | ||||
