Submission #305919

#TimeUsernameProblemLanguageResultExecution timeMemory
305919myungwoo버섯 세기 (IOI20_mushrooms)C++17
80.43 / 100
11 ms416 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

int count_mushrooms(int N)
{
	int K = 137;
	vector<int> arr[2] = {{0}, {}};
	int pt = 1;
	// Step 1: Check type of mushroom one by one
	while (pt < N){
		arr[use_machine({0, pt})].push_back(pt);
		pt++;
		if (arr[0].size() >= 2 || arr[1].size() >= 2) break;
	}
	// Step 2: Check type of mushroom two by one
	while (pt < N){
		int t = arr[1].size() >= 2;
		vector<int> test = {arr[t][0], pt, arr[t][1]};
		if (pt+1 < N) test.push_back(pt+1);
		int res = use_machine(test);
		arr[res>>1&1^t].push_back(pt);
		if (pt+1 < N) arr[res&1^t].push_back(pt+1);
		pt += 2;
		if (arr[0].size() >= K || arr[1].size() >= K) break;
	}
	// Step 3: Count number of type 0 mushrooms K by one
	int zero_count = arr[0].size();
	while (pt < N){
		int t = arr[1].size() >= K;
		vector<int> test;
		for (int i=0;pt+i<N&&i<K;i++){
			test.push_back(arr[t][i]);
			test.push_back(pt+i);
		}
		int res = use_machine(test);
		int cnt = res+1>>1;
		if (!t) cnt = test.size()/2-cnt;
		zero_count += cnt;
		pt += K;
	}
	return zero_count;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:22:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   22 |   arr[res>>1&1^t].push_back(pt);
      |       ~~~~~~^~
mushrooms.cpp:23:24: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   23 |   if (pt+1 < N) arr[res&1^t].push_back(pt+1);
      |                     ~~~^~
mushrooms.cpp:25:21: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |   if (arr[0].size() >= K || arr[1].size() >= K) break;
      |       ~~~~~~~~~~~~~~^~~~
mushrooms.cpp:25:43: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |   if (arr[0].size() >= K || arr[1].size() >= K) break;
      |                             ~~~~~~~~~~~~~~^~~~
mushrooms.cpp:30:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |   int t = arr[1].size() >= K;
      |           ~~~~~~~~~~~~~~^~~~
mushrooms.cpp:37:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |   int cnt = res+1>>1;
      |             ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...