# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
222914 | miello | Type Printer (IOI08_printer) | C++11 | 258 ms | 101224 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MXN = 25005;
struct node {
bool finalword = false , need = false;
struct node* alpha[26];
node() {
for(int i = 0 ; i < 26 ; i++){
this->alpha[i] = nullptr;
}
}
};
vector<char> ans;
vector<string> s;
void insert(node* now , string s , int idx , bool fin) {
if(s.size() == idx) {
now->need = true;
return;
}
if(now->alpha[s[idx] - 'a'] == nullptr){
now->alpha[s[idx] - 'a'] = new node();
now->alpha[s[idx] - 'a']->finalword = fin;
}
insert(now->alpha[s[idx] - 'a'] , s , idx + 1 , fin);
}
void dfs(node* now) {
if(now->need) {
ans.push_back('P');
}
for(int i = 0 ; i < 26 ; i++){
if(now->alpha[i] != nullptr) {
if(!now->alpha[i]->finalword) {
ans.push_back('a' + i);
dfs(now->alpha[i]);
ans.push_back('-');
}
}
}
for(int i = 0 ; i < 26 ; i++){
if(now->alpha[i] != nullptr) {
if(now->alpha[i]->finalword) {
ans.push_back('a' + i);
dfs(now->alpha[i]);
}
}
}
}
int main(){
int n;
scanf("%d" ,&n);
for(int i = 0 ; i < n ; i++){
string a;
cin >> a;
s.push_back(a);
}
sort(s.begin() , s.end() , [](string a , string b) {
return a.size() > b.size();
});
node* root = new node();
for(int i = 0 ; i < n ; i++) {
if(i == 0) {
insert(root, s[i], 0, true);
continue;
}
insert(root, s[i], 0, false);
}
// printf("%d" ,root->alpha['p' - 'a']->alpha['r' - 'a']->finalword);
dfs(root);
printf("%d\n", ans.size());
for(auto i : ans) {
printf("%c\n" ,i);
}
}
컴파일 시 표준 에러 (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... |