답안 #197640

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
197640 2020-01-22T05:13:50 Z Sakamotoo Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 139200 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];
	node *b;
	int cnt=0;
	int mark=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->cnt++;
}

void ins2(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->mark=ind;
		now=now->c[ind];
	}
	now->cnt++;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n;
	cin>>n;
	string pan;
	cin>>pan;
	for(int i=2; i<=n; i++){
		string s;
		cin>>s;
		if(s.size()>pan.size()){
			ins(pan);
			pan=s;
		}else {
			ins(s);
		}
	}
	ins2(pan);
//	cout<<"kenapa"<<endl;
	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 wkwk=now->v.size();
		int sk=0;
		for(int j=0; j<wkwk; j++){
			int i=now->v[j];
			if(i!=now->mark||wkwk==1){
				sk=j;
				ind=i;
				break;
			}
		}
		if(ind==0){
			v.push_back('-');
			now=now->b;
		}else {
			v.push_back('a'+ind-1);
			now->v.erase(now->v.begin()+sk);
			now=now->c[ind];
		}
		
	}
	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:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.size(); i++){
               ~^~~~~~~~~
printer.cpp: In function 'void ins2(std::__cxx11::string)':
printer.cpp:44: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:110:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<v.size(); i++){
               ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 23 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 2452 KB Output is correct
2 Correct 52 ms 3164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 8312 KB Output is correct
2 Correct 314 ms 17624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 376 ms 20636 KB Output is correct
2 Correct 106 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 970 ms 51356 KB Output is correct
2 Execution timed out 1089 ms 117216 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 769 ms 39784 KB Output is correct
2 Execution timed out 1086 ms 139200 KB Time limit exceeded
3 Halted 0 ms 0 KB -