답안 #643390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643390 2022-09-22T00:08:19 Z jamezzz 버섯 세기 (IOI20_mushrooms) C++17
100 / 100
9 ms 468 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

int M=103;

int pop(vector<int> &v){
	int x=v.back();
	v.pop_back();
	return x;
}

int count_mushrooms(int n){
	vector<int> v[2],u;
	v[0]={0};
	for(int i=n-1;i>0;--i)u.pb(i);
	
	if(n<=227){
		while(!u.empty()){
			int x=pop(u);
			if(use_machine({0,x})==1)v[1].pb(x);
			else v[0].pb(x);
		}
		return v[0].size();
	}
	
	//phase 1
	for(int i=0;i<2;++i){
		int x=pop(u);
		if(use_machine({0,x})==1)v[1].pb(x);
		else v[0].pb(x);
	}
	int i=0;
	if(v[0].size()<2)i=1;
	int x=pop(u),y=pop(u);
	int res=use_machine({v[i][0],x,v[i][1],y});
	if(res==0)v[i].pb(x),v[i].pb(y);
	else if(res==1)v[i].pb(x),v[1-i].pb(y);
	else if(res==2)v[1-i].pb(x),v[i].pb(y);
	else v[1-i].pb(x),v[1-i].pb(y);
	
	/*
	printf("a: ");
	for(int x:v[0])printf("%d ",x);
	printf("\n");
	printf("b: ");
	for(int x:v[1])printf("%d ",x);
	printf("\n");
	*/
	
	//phase 2
	bool bad=false;
	while(v[0].size()+v[1].size()<2*M-1){
		int x=pop(u),y=pop(u),z=pop(u);
		if(bad){//y and z are different
			int i=0;
			if(v[0].size()<3)i=1;
			int res=use_machine({v[i][0],x,v[i][1],y,v[i][2],z});
			if(res==0)v[i].pb(x),v[i].pb(y),v[i].pb(z);
			else if(res==1)v[i].pb(x),v[i].pb(y),v[1-i].pb(z);
			else if(res==2)v[i].pb(x),v[1-i].pb(y),v[i].pb(z);
			else if(res==3)v[1-i].pb(x),v[i].pb(y),v[1-i].pb(z);
			else if(res==4)v[1-i].pb(x),v[1-i].pb(y),v[i].pb(z);
			else v[1-i].pb(x),v[1-i].pb(y),v[1-i].pb(z);
			bad=false;
		}
		else{
			int i=0;
			if(v[0].size()<3)i=1;
			int res=use_machine({v[i][0],x,v[i][1],y,v[i][2],z});
			if(res==0)v[i].pb(x),v[i].pb(y),v[i].pb(z);
			else if(res==1)v[i].pb(x),v[i].pb(y),v[1-i].pb(z);
			else if(res==2)bad=true,v[i].pb(z);
			else if(res==3)bad=true,v[1-i].pb(z);
			else if(res==4)v[1-i].pb(x),v[1-i].pb(y),v[i].pb(z);
			else v[1-i].pb(x),v[1-i].pb(y),v[1-i].pb(z);
		}
		/*
		printf("%d %d %d\n",x,y,z);
		printf("bad: %d\n",bad);
		printf("a: ");
		for(int x:v[0])printf("%d ",x);
		printf("\n");
		printf("b: ");
		for(int x:v[1])printf("%d ",x);
		printf("\n");
		*/
		if(!bad)continue;
		if(min(v[0].size(),v[1].size())<2){
			z=pop(u);
			u.pb(x),u.pb(y),u.pb(z);
		}
		else{
			int z=pop(u),w=pop(u);
			int i=0;
			if(v[0].size()<3)i=1;
			int res=use_machine({v[1-i][0],x,v[1-i][1],v[i][0],y,v[i][1],z,v[i][2],w});
			if(res==1)v[1-i].pb(x),v[i].pb(y),v[i].pb(z),v[i].pb(w);
			else if(res==2)v[1-i].pb(x),v[i].pb(y),v[i].pb(z),v[1-i].pb(w);
			else if(res==3)v[1-i].pb(x),v[i].pb(y),v[1-i].pb(z),v[i].pb(w);
			else if(res==4)v[1-i].pb(x),v[i].pb(y),v[1-i].pb(z),v[1-i].pb(w);
			else if(res==5)v[i].pb(x),v[1-i].pb(y),v[i].pb(z),v[i].pb(w);
			else if(res==6)v[i].pb(x),v[1-i].pb(y),v[i].pb(z),v[1-i].pb(w);
			else if(res==7)v[i].pb(x),v[1-i].pb(y),v[1-i].pb(z),v[i].pb(w);
			else v[i].pb(x),v[1-i].pb(y),v[1-i].pb(z),v[1-i].pb(w);
			bad=false;
		}
	}
	
	//phase 3
	int extra[2]={0,0};
	while(!u.empty()){
		int i=0;
		if(v[0].size()<v[1].size())i=1;
		int t=min(v[i].size(),u.size());
		vector<int> m;
		for(int x=0;x<t;++x){
			m.pb(v[i][x]);m.pb(pop(u));
		}
		int res=use_machine(m);
		if(res%2==1)v[1-i].pb(m.back());
		else v[i].pb(m.back());
		extra[i]+=(t-1)-res/2,extra[1-i]+=res/2;
	}
	
	return v[0].size()+extra[0];
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:55:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   55 |  while(v[0].size()+v[1].size()<2*M-1){
      |        ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 2 ms 208 KB Output is correct
7 Correct 5 ms 464 KB Output is correct
8 Correct 5 ms 432 KB Output is correct
9 Correct 6 ms 464 KB Output is correct
10 Correct 6 ms 464 KB Output is correct
11 Correct 5 ms 464 KB Output is correct
12 Correct 6 ms 464 KB Output is correct
13 Correct 7 ms 464 KB Output is correct
14 Correct 4 ms 336 KB Output is correct
15 Correct 6 ms 464 KB Output is correct
16 Correct 6 ms 464 KB Output is correct
17 Correct 4 ms 336 KB Output is correct
18 Correct 7 ms 464 KB Output is correct
19 Correct 6 ms 464 KB Output is correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 5 ms 464 KB Output is correct
22 Correct 6 ms 464 KB Output is correct
23 Correct 5 ms 464 KB Output is correct
24 Correct 5 ms 336 KB Output is correct
25 Correct 5 ms 464 KB Output is correct
26 Correct 6 ms 464 KB Output is correct
27 Correct 6 ms 464 KB Output is correct
28 Correct 6 ms 464 KB Output is correct
29 Correct 6 ms 464 KB Output is correct
30 Correct 6 ms 464 KB Output is correct
31 Correct 7 ms 464 KB Output is correct
32 Correct 6 ms 464 KB Output is correct
33 Correct 5 ms 464 KB Output is correct
34 Correct 5 ms 464 KB Output is correct
35 Correct 6 ms 464 KB Output is correct
36 Correct 8 ms 464 KB Output is correct
37 Correct 5 ms 464 KB Output is correct
38 Correct 5 ms 464 KB Output is correct
39 Correct 5 ms 464 KB Output is correct
40 Correct 6 ms 464 KB Output is correct
41 Correct 5 ms 464 KB Output is correct
42 Correct 6 ms 464 KB Output is correct
43 Correct 6 ms 464 KB Output is correct
44 Correct 6 ms 464 KB Output is correct
45 Correct 6 ms 464 KB Output is correct
46 Correct 5 ms 464 KB Output is correct
47 Correct 8 ms 464 KB Output is correct
48 Correct 6 ms 464 KB Output is correct
49 Correct 9 ms 464 KB Output is correct
50 Correct 7 ms 464 KB Output is correct
51 Correct 8 ms 464 KB Output is correct
52 Correct 6 ms 464 KB Output is correct
53 Correct 6 ms 464 KB Output is correct
54 Correct 5 ms 464 KB Output is correct
55 Correct 6 ms 464 KB Output is correct
56 Correct 6 ms 468 KB Output is correct
57 Correct 5 ms 464 KB Output is correct
58 Correct 5 ms 464 KB Output is correct
59 Correct 5 ms 464 KB Output is correct
60 Correct 6 ms 464 KB Output is correct
61 Correct 7 ms 464 KB Output is correct
62 Correct 0 ms 208 KB Output is correct
63 Correct 0 ms 208 KB Output is correct
64 Correct 0 ms 208 KB Output is correct
65 Correct 0 ms 208 KB Output is correct
66 Correct 1 ms 208 KB Output is correct
67 Correct 0 ms 208 KB Output is correct
68 Correct 0 ms 208 KB Output is correct
69 Correct 0 ms 208 KB Output is correct
70 Correct 0 ms 208 KB Output is correct
71 Correct 1 ms 208 KB Output is correct
72 Correct 0 ms 208 KB Output is correct
73 Correct 0 ms 208 KB Output is correct
74 Correct 0 ms 208 KB Output is correct
75 Correct 1 ms 208 KB Output is correct
76 Correct 0 ms 208 KB Output is correct
77 Correct 0 ms 208 KB Output is correct
78 Correct 0 ms 208 KB Output is correct
79 Correct 1 ms 208 KB Output is correct
80 Correct 0 ms 208 KB Output is correct
81 Correct 0 ms 208 KB Output is correct
82 Correct 0 ms 208 KB Output is correct
83 Correct 0 ms 208 KB Output is correct
84 Correct 1 ms 208 KB Output is correct
85 Correct 0 ms 208 KB Output is correct
86 Correct 0 ms 208 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 0 ms 208 KB Output is correct
89 Correct 0 ms 208 KB Output is correct
90 Correct 0 ms 208 KB Output is correct
91 Correct 0 ms 208 KB Output is correct