Submission #197618

# Submission time Handle Problem Language Result Execution time Memory
197618 2020-01-22T03:35:11 Z Sakamotoo Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 145260 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;

#define mp make_pair
#define fi first
#define se second

//mt19937 rng(time(NULL)); //int
mt19937_64 rng(time(NULL)); //Long Long
//shuffle(a.begin(),a.end(),rng); //shuffle
//rng(); //random

struct node{
	vector<int> v;
	node *c[30];
	int val=0;
	int awal=0;
	node *b;
	int cnt=0;
	int maxi=0;
};

node *root= new node;

void ins(string s){
	node *now=root;
	for(int i=0; i<s.size(); i++){
		int ind=s[i]-'a'+1;
		if(now->c[ind]==NULL){
			now->c[ind]=new node;
			now->c[ind]->b=now;
			now->v.push_back(ind);
		}
		now=now->c[ind];
		now->val=1;
		now->maxi=max(now->maxi,(int)s.size()-i);
	}
	now->cnt++;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin>>n;
	root->awal=1;
	for(int i=1; i<=n; i++){
		string s;
		cin>>s;
		ins(s);
	}
	int pri=0;
	node *now=root;
	vector<char> v; 
	while(true){
		if(pri==n) break; 
		if(now->cnt>0){
			now->cnt--;
			v.push_back('P');
			pri++;
			continue;
		}
		int ind=0;
		int lol=1e9;
		int wkwk=now->v.size();
		for(int j=0; j<wkwk; j++){
			int i=now->v[j];
			if(now->c[i]==NULL){
				
			}else if(now->c[i]->val>0&&now->c[i]->maxi<lol){
				ind=i;
				lol=now->c[i]->maxi;
			}
		}
		if(ind==0){
			v.push_back('-');
			now=now->b;
		}else {
			v.push_back('a'+ind-1);
			now=now->c[ind];
			now->val--;
		}
		
	}
	cout<<v.size()<<endl;
	for(int i=0; i<v.size(); i++){
		cout<<v[i]<<endl;
	}
}

Compilation message

printer.cpp: In function 'void ins(std::__cxx11::string)':
printer.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:92:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 25 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 2684 KB Output is correct
2 Correct 53 ms 3372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 8736 KB Output is correct
2 Correct 334 ms 18312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 387 ms 21544 KB Output is correct
2 Correct 116 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 968 ms 53644 KB Output is correct
2 Execution timed out 1034 ms 122284 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 803 ms 41588 KB Output is correct
2 Execution timed out 1046 ms 145260 KB Time limit exceeded
3 Halted 0 ms 0 KB -