답안 #1073730

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073730 2024-08-24T19:29:55 Z thatsgonzalez 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

#define pb push_back



int count_mushrooms(int n) {
	int ans = 1;
	vector<int> a; a.pb(0);
	vector<int> b; 

	int res = use_machine({0,1,2});

	if(res == 0){
		ans+=2;
		a.pb(1); a.pb(2);
	}
	else if(res == 2){
		ans++;
		a.pb(2); b.pb(1);
	}
	else{
		res = use_machine({0,1});
		if(res){
			b.pb(1); b.pb(2);
		}
		else{
			ans++;
			a.pb(1); b.pb(2);
		}
	}

	int ind = 3;
	while(ind<n){
		vector <int> q; int how = 0;
		if(a.size()>=b.size()){
			for(int i = 0; i<a.size() and ind<n; i++){
				q.pb(ind); q.pb(a[i]); ind++; how++;
			}
			res = use_machine(q);
			if(res&1){
				b.pb(ind);
			}
			else a.pb(ind);
			ans += how-(res)/2;
		}
		else{
			for(int i = 0; i<b.size() and ind<n; i++){
				q.pb(ind); q.pb(b[i]); ind++; how++;
			}
			res = use_machine(q);
			if(res&1) a.pb(ind);
			else b.pb(ind);
			ans += res/2 + (res&1);
		}	
	}

	return ans;
}

Compilation message

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