# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
499100 | rampu | Type Printer (IOI08_printer) | C++14 | 94 ms | 77052 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
struct node {
bool w = false;
bool l = false;
int next[26];
};
node trie[700000];
int t = 0;
int maxi;
string word, larger;
void insert(const string &word, bool p) {
int node = 0;
for (int i = 0; i < word.size(); i++) {
int letter = (word[i] - 'a');
trie[node].next[letter] = trie[node].next[letter] ? trie[node].next[letter] : ++t;
node = trie[node].next[letter];
trie[node].l = p;
}
trie[node].w = true;
trie[node].l = p;
}
string ans;
void dfs(int node) {
if (trie[node].w) ans += "P";
int pending = -1, next_node;
for (int i = 0; i < 26; i++) {
if (trie[node].next[i]) {
next_node = trie[node].next[i];
if (trie[next_node].l) {
pending = i;
continue;
}
ans.push_back(i + 'a');
dfs(next_node);
ans += "-";
}
}
if (pending != -1) {
ans.push_back(pending + 'a');
dfs(trie[node].next[pending]);
}
}
int main() {
ios_base :: sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> word;
insert(word, 0);
if (word.size() >= maxi) {
maxi = word.size();
larger = word;
}
}
insert(larger, 1);
dfs(0);
cout << ans.size() << '\n';
for(int i = 0; i < ans.size(); i++)
cout << ans[i] << '\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... |