제출 #305852

#제출 시각아이디문제언어결과실행 시간메모리
305852myungwoo버섯 세기 (IOI20_mushrooms)C++17
75.59 / 100
11 ms384 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)

int count_mushrooms(int N)
{
	const int K = 100;
	int add = 0;
	vector <int> arr[2];
	arr[0] = {0};
	for (int i=1;i<N;i++){
		if (arr[0].size() >= K){
			vector <int> test;
			for (int j=0;j<K&&i+j<N;j++){
				test.push_back(arr[0][j]);
				test.push_back(i+j);
			}
			int res = use_machine(test);
			add += test.size()>>1;
			add -= res&1;
			add -= res>>1;
			i += K-1;
		}
		else if (arr[1].size() >= K){
			vector <int> test;
			for (int j=0;j<K&&i+j<N;j++){
				test.push_back(arr[1][j]);
				test.push_back(i+j);
			}
			int res = use_machine(test);
			add += res&1;
			add += res>>1;
			i += K-1;
		}
		else if (i+1 < N && arr[0].size() > 1){
			int res = use_machine({arr[0][0], i, arr[0][1], i+1});
			arr[res>>1&1].push_back(i);
			arr[res&1].push_back(++i);
		}else if (i+1 < N && arr[1].size() > 1){
			int res = use_machine({arr[1][0], i, arr[1][1], i+1});
			arr[res>>1&1^1].push_back(i);
			arr[res&1^1].push_back(++i);
		}
		else arr[use_machine({0, i})].push_back(i);
	} 
	return arr[0].size() + add;
}

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:43:14: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   43 |    arr[res>>1&1^1].push_back(i);
      |        ~~~~~~^~
mushrooms.cpp:44:11: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   44 |    arr[res&1^1].push_back(++i);
      |        ~~~^~
#Verdict Execution timeMemoryGrader output
Fetching results...