# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
518266 | plains4 | Type Printer (IOI08_printer) | C++14 | 179 ms | 96968 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int CHAR_COUNT = 26;
struct node {
bool cnt_leaf;
short max_depth;
unordered_map<short, node*> nx;
node() {
cnt_leaf = max_depth = 0;
}
};
string ans;
node *root = new node();
node* insert(node *cur, string &s, int dep) {
if(s.length() == dep){
cur->cnt_leaf = true;
cur->max_depth = max(cur->max_depth, (short)dep);
return cur;
}
int ch = s[dep] - 'a';
if(cur->nx.count(ch) == 0)cur->nx[ch] = new node();
cur->nx[ch] = insert(cur->nx[ch], s, dep + 1);
cur->max_depth = max(cur->max_depth, cur->nx[ch]->max_depth);
// cout << "Done Traverse from " << s[dep] << " -> " << (int)s[dep] << " " << cur->max_depth << endl;
return cur;
}
void print(node *cur){
if(cur == NULL)return;
int last = -1;
short maxi = -1;
for(auto x: cur->nx) {
// cout << "exist to " << (char)(i) << endl;
if(maxi < x.second->max_depth){
maxi = x.second->max_depth;
last = x.first;
}
}
if(cur->cnt_leaf > 0)ans += "P";
for(auto x: cur->nx){
if(x.first == last)continue;
// cout << "Print Traverse to " << (char)(i) << " -> " << i << endl;
ans += (char)(x.first + 'a');
print(x.second);
ans += "-";
}
if(last != -1){
ans += (char)(last + 'a');
print(cur->nx[last]);
ans += "-";
}
}
int main(){
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n; cin >> n;
while(n--){
string s; cin >> s;
root = insert(root, s, 0);
}
// cout << sizeof(root->nx) + sizeof(root->cnt_leaf) + sizeof(root->max_depth) << endl;
// cout << "Start Root" << endl;
print(root);
while(ans.size() > 0 && ans.back() == '-') ans.pop_back();
cout << ans.size() << "\n";
for(int i = 0; i < ans.size(); i++){
cout << ans[i] << "\n";
}
}
컴파일 시 표준 에러 (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... |