# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
120424 | miello | Type Printer (IOI08_printer) | C++11 | 104 ms | 70508 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ii pair<int,int>
using namespace std;
struct node{
struct node *alpha[26];
bool endofword , el;
int sz;
};
int num[26];
vector<ii> v;
queue<char> q;
int word , n;
void backtrack(node *h , int now){
v.clear();
q.push('a' + now);
if(h->el){
q.push('P');
word++;
}
int mx = -1;
for(int i = 0 ; i < 26 ; i++){
if(h->alpha[i] != NULL){
v.emplace_back(h->sz , i);
}
}
sort(v.begin(),v.end());
for(auto i : v){
int u = i.second;
backtrack(h->alpha[u] , u);
}
if(word != n)q.push('-');
}
node* getnew(){
node *x = new node;
x->endofword = 0;
x->el = 0;
x->sz = 0;
for(int i = 0 ; i < 26 ; i++){
x->alpha[i] = NULL;
}
return x;
}
int getsz(node *p){
int sz = 1;
if(p->endofword){
p->sz = 1;
return sz;
}
for(int i = 0 ; i < 26 ; i++){
if(p->alpha[i] != NULL){
sz += getsz(p->alpha[i]);
}
}
p->sz = sz;
return sz;
}
int main(){
scanf("%d",&n);
node *head = getnew();
for(int i = 0 ; i < n ; i++){
string s;
cin >> s;
int l = s.size();
node *x;
x = head;
for(int j = 0 ; j < l ; j++){
if(x->alpha[s[j] - 'a'] == NULL){
x->alpha[s[j] - 'a'] = getnew();
x->endofword = 0;
x->alpha[s[j] - 'a']->endofword = 1;
}
x = x->alpha[s[j] - 'a'];
}
x->el = 1;
}
for(int i = 0 ; i < 26 ; i++){
if(head->alpha[i] != NULL){
v.emplace_back(getsz(head->alpha[i]) , i);
}
}
sort(v.begin() , v.end());
for(auto i : v){
int u = i.second;
backtrack(head->alpha[u] , u);
}
printf("%d\n",q.size());
while(q.size()){
printf("%c\n",q.front());
q.pop();
}
}
컴파일 시 표준 에러 (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... |