Submission #600573

# Submission time Handle Problem Language Result Execution time Memory
600573 2022-07-21T05:21:33 Z kig9981 Counting Mushrooms (IOI20_mushrooms) C++17
92.623 / 100
9 ms 464 KB
#include "mushrooms.h"
#include <bits/stdc++.h>

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

vector<pair<int,int>> V;
vector<int> A, B, Q;
int D[3];

void query2()
{
	int a=V[0].first, b=V[1].first, r;
	if(A.size()>1) {
		r=use_machine({A[0],a,A[1],b});
		if(r&1) {
			B.push_back(b);
			A.push_back(V[1].second);
		}
		else {
			A.push_back(b);
			B.push_back(V[1].second);
		}
		if(r>1) {
			B.push_back(a);
			A.push_back(V[0].second);
		}
		else {
			A.push_back(a);
			B.push_back(V[0].second);
		}
	}
	else {
		r=use_machine({B[0],a,B[1],b});
		if(r&1) {
			A.push_back(b);
			B.push_back(V[1].second);
		}
		else {
			B.push_back(b);
			A.push_back(V[1].second);
		}
		if(r>1) {
			A.push_back(a);
			B.push_back(V[0].second);
		}
		else {
			B.push_back(a);
			A.push_back(V[0].second);
		}
	}
	V.clear();
}

void query3()
{
	int a, b, c, r;
	if(Q.size()==1) {
		a=Q.back(); Q.pop_back();
		if(use_machine({0,a})) B.push_back(a);
		else A.push_back(a);
	}
	else if(Q.size()==2) {
		a=Q.back(); Q.pop_back();
		b=Q.back(); Q.pop_back();
		if(A.size()>1) {
			r=use_machine({A[0],a,A[1],b});
			if(r&1) B.push_back(b);
			else A.push_back(b);
			if(r>1) B.push_back(a);
			else A.push_back(a);
		}
		else {
			r=use_machine({B[0],a,B[1],b});
			if(r&1) A.push_back(b);
			else B.push_back(b);
			if(r>1) A.push_back(a);
			else B.push_back(a);
		}
	}
	else {
		a=Q.back(); Q.pop_back();
		b=Q.back(); Q.pop_back();
		c=Q.back(); Q.pop_back();
		if(A.size()>1) {
			r=use_machine({A[0],a,A[1],b,c});
			if(r&1) B.push_back(c);
			else A.push_back(c);
			if(r==0) {
				A.push_back(a);
				A.push_back(b);
			}
			else if(r==1) {
				A.push_back(a);
				Q.push_back(b);
			}
			else if(r==2) {
				V.emplace_back(a,b);
				if(V.size()>1) query2();
			}
			else if(r==3) {
				B.push_back(a);
				Q.push_back(b);
			}
			else {
				B.push_back(a);
				B.push_back(b);
			}
		}
		else {
			r=use_machine({B[0],a,B[1],b,c});
			if(r&1) A.push_back(c);
			else B.push_back(c);
			if(r==0) {
				B.push_back(a);
				B.push_back(b);
			}
			else if(r==1) {
				B.push_back(a);
				Q.push_back(b);
			}
			else if(r==2) {
				V.emplace_back(a,b);
				if(V.size()>1) query2();
			}
			else if(r==3) {
				A.push_back(a);
				Q.push_back(b);
			}
			else {
				A.push_back(a);
				A.push_back(b);
			}
		}
	}
}

int query()
{
	int m=min(Q.size(),max(A.size(),B.size())+1), r;
	vector<int> I;
	if(Q.size()<3) {
		query3();
		return 0;
	}
	if(A.size()>=m-1) {
		for(int i=0;i<m-1;i++) {
			I.push_back(A[i]); I.push_back(Q.back());
			Q.pop_back();
		}
		I.push_back(Q.back()); Q.pop_back();
		r=use_machine(I);
		if(r&1) {
			B.push_back(I.back());
			Q.push_back(I[I.size()-2]);
			return m-2-(r>>1);
		}
		else A.push_back(I.back());
		return m-1-(r>>1);
	}
	else {
		for(int i=0;i<m-1;i++) {
			I.push_back(B[i]); I.push_back(Q.back());
			Q.pop_back();
		}
		I.push_back(Q.back()); Q.pop_back();
		r=use_machine(I);
		if(r&1) {
			A.push_back(I.back());
			Q.push_back(I[I.size()-2]);
		}
		else B.push_back(I.back());
		return r>>1;
	}
}

int count_mushrooms(int n)
{
	int ret=0;
	mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
	if(n-1<=226) {
		ret=1;
		for(int i=1;i<n;i++) ret+=!use_machine({0,i});
		return ret;
	}
	for(int i=1;i<n;i++) Q.push_back(i);
	shuffle(Q.begin(),Q.end(),mt);
	A.push_back(0);
	while(max(A.size(),B.size())<2) {
		int c=Q.back();
		Q.pop_back();
		if(use_machine({0,c})) B.push_back(c);
		else A.push_back(c);
	}
	for(int i=0;i<75;i++) {
		if(Q.empty()) break;
		query3();
	}
	if(V.size()) {
		if(use_machine({0,V[0].first})) {
			B.push_back(V[0].first);
			A.push_back(V[0].second);
		}
		else {
			A.push_back(V[0].first);
			B.push_back(V[0].second);
		}
	}
	while(Q.size()) ret+=query();
	return ret+A.size();
}

Compilation message

mushrooms.cpp: In function 'int query()':
mushrooms.cpp:153:13: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  153 |  if(A.size()>=m-1) {
      |     ~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 7 ms 464 KB Output is correct
8 Correct 5 ms 464 KB Output is correct
9 Correct 7 ms 464 KB Output is correct
10 Correct 9 ms 464 KB Output is correct
11 Correct 6 ms 464 KB Output is correct
12 Correct 6 ms 464 KB Output is correct
13 Correct 6 ms 464 KB Output is correct
14 Correct 3 ms 336 KB Output is correct
15 Partially correct 8 ms 464 KB Output is partially correct
16 Partially correct 7 ms 464 KB Output is partially correct
17 Correct 4 ms 336 KB Output is correct
18 Correct 6 ms 464 KB Output is correct
19 Partially correct 7 ms 464 KB Output is partially correct
20 Correct 5 ms 464 KB Output is correct
21 Correct 9 ms 464 KB Output is correct
22 Partially correct 7 ms 464 KB Output is partially correct
23 Correct 7 ms 464 KB Output is correct
24 Correct 3 ms 336 KB Output is correct
25 Partially correct 6 ms 464 KB Output is partially correct
26 Partially correct 7 ms 464 KB Output is partially correct
27 Correct 7 ms 464 KB Output is correct
28 Partially correct 6 ms 464 KB Output is partially correct
29 Partially correct 7 ms 464 KB Output is partially correct
30 Partially correct 6 ms 464 KB Output is partially correct
31 Partially correct 6 ms 464 KB Output is partially correct
32 Partially correct 7 ms 464 KB Output is partially correct
33 Partially correct 7 ms 464 KB Output is partially correct
34 Partially correct 7 ms 464 KB Output is partially correct
35 Partially correct 7 ms 464 KB Output is partially correct
36 Partially correct 7 ms 464 KB Output is partially correct
37 Partially correct 6 ms 464 KB Output is partially correct
38 Partially correct 6 ms 464 KB Output is partially correct
39 Partially correct 7 ms 464 KB Output is partially correct
40 Partially correct 6 ms 464 KB Output is partially correct
41 Partially correct 8 ms 464 KB Output is partially correct
42 Partially correct 6 ms 464 KB Output is partially correct
43 Partially correct 7 ms 464 KB Output is partially correct
44 Partially correct 6 ms 464 KB Output is partially correct
45 Partially correct 6 ms 464 KB Output is partially correct
46 Partially correct 9 ms 464 KB Output is partially correct
47 Partially correct 7 ms 464 KB Output is partially correct
48 Partially correct 7 ms 464 KB Output is partially correct
49 Partially correct 6 ms 464 KB Output is partially correct
50 Partially correct 6 ms 464 KB Output is partially correct
51 Partially correct 7 ms 464 KB Output is partially correct
52 Partially correct 8 ms 464 KB Output is partially correct
53 Partially correct 7 ms 464 KB Output is partially correct
54 Partially correct 7 ms 464 KB Output is partially correct
55 Partially correct 6 ms 464 KB Output is partially correct
56 Partially correct 7 ms 464 KB Output is partially correct
57 Partially correct 6 ms 464 KB Output is partially correct
58 Partially correct 6 ms 464 KB Output is partially correct
59 Partially correct 7 ms 464 KB Output is partially correct
60 Partially correct 7 ms 464 KB Output is partially correct
61 Partially correct 8 ms 464 KB Output is partially correct
62 Correct 0 ms 208 KB Output is correct
63 Correct 1 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 0 ms 208 KB Output is correct
67 Correct 1 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 0 ms 208 KB Output is correct
72 Correct 0 ms 208 KB Output is correct
73 Correct 1 ms 208 KB Output is correct
74 Correct 0 ms 208 KB Output is correct
75 Correct 0 ms 208 KB Output is correct
76 Correct 0 ms 208 KB Output is correct
77 Correct 0 ms 216 KB Output is correct
78 Correct 0 ms 208 KB Output is correct
79 Correct 0 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 0 ms 208 KB Output is correct
85 Correct 0 ms 208 KB Output is correct
86 Correct 1 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 1 ms 208 KB Output is correct