답안 #223690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
223690 2020-04-16T05:03:18 Z miello Type Printer (IOI08_printer) C++11
30 / 100
90 ms 71672 KB
#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();
	}
}

Compilation message

printer.cpp: In function 'void backtrack(node*, int)':
printer.cpp:24:6: warning: unused variable 'mx' [-Wunused-variable]
  int mx = -1;
      ^~
printer.cpp: In function 'int main()':
printer.cpp:93:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::queue<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",q.size());
                ~~~~~~~~^
printer.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 3432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 11416 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 39 ms 28536 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 90 ms 71672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 85 ms 55800 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -