Submission #120423

# Submission time Handle Problem Language Result Execution time Memory
120423 2019-06-24T12:43:26 Z miello Type Printer (IOI08_printer) C++11
30 / 100
89 ms 36472 KB
#include <bits/stdc++.h>
#define ii pair<int,int>
using namespace std;

struct node{
	struct node *alpha[26];
	bool endofword , el;
};

int num[26];

vector<ii> v;
queue<char> q;
int word , n;

void backtrack(node *h , int now){
	q.push('a' + now);
	if(h->el){
		q.push('P');
		word++;
	}
	for(int i = 0 ; i < 26 ; i++){
		if(h->alpha[i] != NULL){
			backtrack(h->alpha[i] , i);
		}
	}
	if(word != n)q.push('-');
}

node* getnew(){
	node *x = new node;
	x->endofword = 0;
	x->el = 0;
	for(int i = 0 ; i < 26 ; i++){
		x->alpha[i] = NULL;
	}
	return x;
}

int getsz(node *p){
	int sz = 1;
	if(p->endofword){
		return 1;
	}
	for(int i = 0 ; i < 26 ; i++){
		if(p->alpha[i] != NULL){
			sz += getsz(p->alpha[i]);
		}
	}
	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 'int main()':
printer.cpp:82: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:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 5888 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 14712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 36472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 78 ms 28536 KB Output isn't correct
2 Halted 0 ms 0 KB -