답안 #1064801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1064801 2024-08-18T17:53:50 Z thatsgonzalez 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
0 ms 344 KB
#include "mushrooms.h"

int count_mushrooms(int n) {
	if(n == 2){
		int res = use_machine({0,1});
		if(res) return 1;
		else return 2;
	}
	int ans = 1;
	int b = -1;
	for(int i = 1; i<n-1; i+=2){

		if(i==n-1){
			int res = use_machine({0,i});
			if(!res) ans++;
			break; 
		}

		int res = use_machine({0,i,i+1});
		if(res == 2) ans++;
		else if(res == 0) ans+=2;
		else{
			if(use_machine({0,i})){
				b = i+1;
			}
			else{
				ans++; b = i+1;
			}
		}
	}
	int a = -1;
	for(int i = b+1; i<n-1 and b>=0; i+=2){
		if(i==n-1){
			int res = use_machine({0,i});
			if(!res) ans++;
			break; 
		}
		int res = use_machine({b,i,i+1});
		if(res == 2) ans++;
		else if(res == 1){
			if(use_machine({b,i})){
				ans+=2; a = i+1;
			}
			else{
				ans++; a = i+1;
			}
		}
	}

	for(int i = a+1; i<n-1 and a>=0; i+=2){
		if(i==n-1){
			int res = use_machine({0,i});
			if(!res) ans++;
			break; 
		}
		int res = use_machine({0,i,a,i+1});
		if(res == 1 || res == 2){
			ans++;
		}
		else if(res == 0) ans+=2;
	}

	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Answer is not correct.
3 Halted 0 ms 0 KB -