Submission #884577

# Submission time Handle Problem Language Result Execution time Memory
884577 2023-12-07T17:17:01 Z jamjanek Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
0 ms 344 KB
#include<bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
const int stala = 6;

int maska[9] = {0,0,56,7,52,23,53,21,60,};
vector<int>zapytanie[9] = {{4,1,6,2,5,0,3,},{},{0,5,6,1,3,2,4,},{},{},{2,5,1,3,0,4,},{4,1,5,6,0,3,2,},{2,5,6,0,3,},{6,5,4,3,2,1,0,},};
vector<int>graf[9] = {{1,2,8,7,8,8,8,},{},{-1,2,3,4,5,6,7,3,-1,4,-1,3,4,5,6,7,-1,-1,-1,3,4,5,6,},{},{},{3,4,5,},{-1,-1,-1,3,4,5,-1,3,4,5,-1,-1,3,4,-1,5,-1,3,4,5,-1,-1,3,4,5,6,},{-1,2,8,8,8,-1,3,4,5,},{-1,2,5,6,6,6,6,-1,3,4,5,6,7,-1,3,4,5,6,7,-1,3,4,5,6,7,-1,2,7,6,6,7,-1,2,3,4,5,6,7,},};

vector<int>A[2];
int Ac[2];
int it;
int count_mushrooms1(int n){
	while(it<n){
//		printf("it = %d\n", it);
		vector<int>pom;
		bool czy = 0;
		if(A[1].size()>A[0].size())czy = 1;
		int pom1 = 0;
		while(it<n && pom.size()<2*A[czy].size()){
			pom.push_back(A[czy][pom1++]);
			pom.push_back(it);
			it++;
		}
		int ans = use_machine(pom);
//		printf("vec: = ");for(auto j: pom)printf("%d ", j);printf("\n");
//		printf("ans = %d\n", ans);
		if(ans%2==0)
			A[czy].push_back(it-1);
		else
			A[!czy].push_back(it-1);
		Ac[!czy]+=(ans+1)/2;
		Ac[czy]+=pom1-(ans+1)/2;
		if(pom1==2){
			if(ans<2)
				A[czy].push_back(it-2);
			else
				A[!czy].push_back(it-2);
		}
	}
//	printf("res = %d\n", Ac[0]);
	return Ac[0];
}
int count_mushrooms(int n){
	A[0].push_back(0);
	it = 1;
	Ac[0] = 1;
	Ac[1] = 0;
	if(n<=stala)
		return count_mushrooms1(n);
	int x = 0;
	while(graf[x].size()>0){
		int c = use_machine(zapytanie[x]);
		x = graf[x][c];
	}
	x = maska[x];
	for(int i=0;i<stala;i++){
		if((x>>i)&1){
			A[1].push_back(i+1);
			Ac[1]++;
		}
		else{
			A[0].push_back(i+1);
			Ac[0]++;
		}
	}
	it = stala+1;
	return count_mushrooms1(n);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 340 KB Answer is not correct.
4 Halted 0 ms 0 KB -