Submission #305914

#TimeUsernameProblemLanguageResultExecution timeMemory
305914myungwoo버섯 세기 (IOI20_mushrooms)C++17
25 / 100
127 ms632 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

int count_mushrooms(int N)
{
	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;
	}
	return arr[0].size();
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:21:13: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   21 |   arr[res>>1&1^t].push_back(pt);
      |       ~~~~~~^~
mushrooms.cpp:22:24: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   22 |   if (pt+1 < N) arr[res&1^t].push_back(pt+1);
      |                     ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...