답안 #1052206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052206 2024-08-10T12:29:48 Z noyancanturk 버섯 세기 (IOI20_mushrooms) C++17
0 / 100
0 ms 344 KB
#include "mushrooms.h"

#include <bits/stdc++.h>
using namespace std;

#define pb push_back

int ind=1;
vector<int>t1,t2;

int count_mushrooms(int n) {
	t1.pb(0);
	while(ind<n&&t1.size()<2&&t2.size()<2){
		int k=use_machine({0,ind});
		if(k==1){
			t2.pb(ind);
		}else{
			t1.pb(ind);
		}
		ind++;
	}
	for(int i=0;i<100&&ind<n;i++){
		if(ind==n-1){
			int k=use_machine({0,ind});
			if(k==1){
				t2.pb(ind);
			}else{
				t1.pb(ind);
			}
			ind++;
		}else if(1<t1.size()){
			int k=use_machine({t1[0],ind,t1[1],ind+1});
			if(!k){
				t1.pb(ind);
				t1.pb(ind+1);
			}else if(k==1){
				t1.pb(ind);
				t2.pb(ind+1);
			}else if(k==2){
				t2.pb(ind);
				t1.pb(ind+1);
			}else{
				t2.pb(ind);
				t2.pb(ind+1);
			}
		}else{
			int k=use_machine({t2[0],ind,t2[1],ind+1});
			if(!k){
				t2.pb(ind);
				t2.pb(ind+1);
			}else if(k==1){
				t2.pb(ind);
				t1.pb(ind+1);
			}else if(k==2){
				t1.pb(ind);
				t2.pb(ind+1);
			}else{
				t1.pb(ind);
				t1.pb(ind+1);
			}
		}
	}
	int ans=0;
	while(ind<n){
		if(t2.size()<t1.size()){
			vector<int>to;
			int j=ind;
			to.pb(t1[0]);
			for(int i=1;i<t1.size()&&j<n;i++){
				to.pb(j++);
				to.pb(t1[i]);
			}
			if(j<n){
				to.pb(j);
				int k=use_machine(to);
				ans+=(j-ind)-k/2;
				if(k&1)t2.pb(j);
				else t1.pb(j);
				j++;
			}else{
				int k=use_machine(to);
				ans+=(j-ind)-k/2;
			}
			ind=j;
		}else{
			vector<int>to;
			int j=ind;
			to.pb(t2[0]);
			for(int i=1;i<t2.size()&&j<n;i++){
				to.pb(j++);
				to.pb(t2[i]);
			}
			if(j<n){
				to.pb(j);
				int k=use_machine(to);
				ans+=k/2;
				if(k&1)t1.pb(j);
				else t2.pb(j);
				j++;
			}else{
				int k=use_machine(to);
				ans+=k/2;
			}
			ind=j;
		}
	}
	return ans+t1.size();
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:69:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |    for(int i=1;i<t1.size()&&j<n;i++){
      |                ~^~~~~~~~~~
mushrooms.cpp:89:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |    for(int i=1;i<t2.size()&&j<n;i++){
      |                ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 344 KB Duplicate value 3 in the query array.
4 Halted 0 ms 0 KB -