| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1360252 | minh201643 | Type Printer (IOI08_printer) | C++20 | 109 ms | 105176 KiB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 500005
#define file
////
int n;
struct node {
bool is_end;
int ma, len, val;
node* child[26];
};
node* root;
node* create_node () {
node* res = new node ();
res -> is_end = 0;
for (int i = 0; i < 26; i++) res -> child[i] = NULL;
res -> len = 0;
res -> ma = 0;
res -> val = 0;
return res;
}
void add (string s) {
node* p = root;
for (char c : s) {
if (p -> child[c - 'a'] == NULL) p -> child[c - 'a'] = create_node ();
p = p -> child[c - 'a'];
}
p -> is_end = 1;
}
void dfs (node* u) {
u -> val += u -> is_end;
for (int i = 0; i < 26; i++) {
if (u -> child[i] == NULL) continue;
node* v = u -> child[i];
dfs (v);
u -> len += v -> len + 2;
u -> val += v -> val;
u -> ma = max (u -> ma, v -> ma + 1);
}
}
int tg, ok = 0;
void print_1 (node* u) {
if (u -> is_end) cout << "P\n";
for (int i = 0; i < 26; i++) {
if (u -> child[i] == NULL) continue;
node* v = u -> child[i];
if (v -> ma + 1 == tg && ok == 0) {
ok = 1;
tg = i;
continue;
}
cout << (char)(i + 'a') << '\n';
print_1 (v);
cout << "-\n";
}
}
vector<char> ans;
void print_2 (node* u) {
if (u -> is_end) ans.push_back('P');
vector<pair<int, int> > ve;
for (int i = 0; i < 26; i++) {
if (u -> child[i] == NULL) continue;
node* v = u -> child[i];
if (i != tg && u == root) continue;
ve.push_back({v -> ma, i});
}
sort (ve.begin(), ve.end(), [](const pair<int, int>& x, const pair<int, int>& y){
return x.first < y.first;
});
for (auto x : ve) {
ans.push_back((char)(x.second + 'a'));
print_2 (u -> child[x.second]);
ans.push_back('-');
}
}
void read() {
cin >> n;
root = create_node ();
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
add (s);
}
}
void solve() {
dfs (root);
cout << root -> len - root -> ma + root -> val << '\n';
tg = root -> ma;
print_1 (root);
print_2 (root);
while (ans.size() && ans.back() == '-') ans.pop_back();
for (char c : ans) cout << c << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
if (fopen(file".INP","r")) {
freopen(file".INP","r",stdin);
freopen(file".OUT","w",stdout);
}
read();
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
