제출 #432573

#제출 시각아이디문제언어결과실행 시간메모리
432573saleh버섯 세기 (IOI20_mushrooms)C++17
25 / 100
121 ms512 KiB
#include "mushrooms.h"//
#include <bits/stdc++.h>


using namespace std;


int count_mushrooms(int n) {
	vector<int> m = {0, 1}, nat;
	for (int i = 0; i < n; i++) nat.push_back(0);
	nat[0] = 1;
	int c1 = use_machine(m);
	if (c1 > 0) nat[1] = 2;
	else nat[1] = 1;
	if (n == 2) return 2 - c1;
	m = {0, 2};
	int c2 = use_machine(m);
	if (c2 > 0) nat[2] = 2;
	else nat[2] = 1;
	int tmp = -1, pmt = -1;
	if (c1 == 0) {
		tmp = 0;
		pmt = 1;
	}
	if (c2 == 0) {
		tmp = 0;
		pmt = 2;
	}
	if (c1 == c2 && c1 == 1) {
		tmp = 1;
		pmt = 2;
		for (int i = 3; i + 1 < n; i += 2) {
			m = {tmp, i, pmt, i + 1};
			int chi = use_machine(m);
			if (chi % 2 == 1) nat[i + 1] = 1;
			else nat[i + 1] = 2;
			if (chi >= 2)  nat[i] = 1;
			else nat[i] = 2;
		}
		if (n % 2 == 0) {
			m = {tmp, n - 1};
			if (use_machine(m) > 0) nat[n - 1] = 1;
			else nat[n - 1] = 2;
		}
	} else {
		for (int i = 3; i + 1 < n; i += 2) {
			m = {tmp, i, pmt, i + 1};
			int chi = use_machine(m);
			if (chi % 2 == 1) nat[i + 1] = 2;
			else nat[i + 1] = 1;
			if (chi >= 2)  nat[i] = 2;
			else nat[i] = 1;
		}
		if (n % 2 == 0) {
			m = {tmp, n - 1};
			if (use_machine(m) > 0) nat[n - 1] = 2;
			else nat[n - 1] = 1;
		}
	}
	return count(nat.begin(), nat.end(), 1);
}

//int main() {}//
#Verdict Execution timeMemoryGrader output
Fetching results...