# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1021675 | TrendBattles | Type Printer (IOI08_printer) | C++14 | 103 ms | 56520 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
#define INFILE "printer.inp"
#define OUTFILE "printer.out"
const int MAX_AL = 26;
struct Node {
int exist = 0;
int child[MAX_AL];
Node() {
memset(child, -1, sizeof child);
}
};
vector <Node> trie(1);
void add(const string& s) {
int now = 0;
for (char x : s) {
int nxt = trie[now].child[x - 'a'];
if (nxt == -1) {
nxt = trie.size();
trie[now].child[x - 'a'] = nxt;
trie.emplace_back();
}
now = nxt;
}
trie[now].exist += 1;
}
string all_operations, longest_string;
void DFS(int u, int tight, int depth) {
for (int i = 1; i <= trie[u].exist; ++i) {
all_operations.push_back('P');
}
for (int i = 0; i < MAX_AL; ++i) {
int v = trie[u].child[i];
if (v == -1) continue;
if (tight and depth < (int) longest_string.size() and longest_string[depth] - 'a' == i) continue;
all_operations.push_back(i + 'a');
DFS(v, 0, depth + 1);
all_operations.push_back('-');
}
if (depth == (int) longest_string.size() or not tight) return;
int v = trie[u].child[longest_string[depth] - 'a'];
all_operations.push_back(longest_string[depth]);
DFS(v, 1, depth + 1);
all_operations.push_back('-');
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
if (fopen(INFILE, "r")) {
freopen(INFILE, "r", stdin);
freopen(OUTFILE, "w", stdout);
}
int N; cin >> N;
for (int i = 0; i < N; ++i) {
string T; cin >> T;
if (longest_string.empty()) longest_string = T;
add(T);
if ((int) longest_string.size() < (int) T.size()) longest_string = T;
}
DFS(0, 1, 0);
while (all_operations.back() == '-') all_operations.pop_back();
cout << (int) all_operations.size() << '\n';
for (char x : all_operations) cout << x << '\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... |