답안 #1055047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1055047 2024-08-12T14:12:32 Z pcc 버섯 세기 (IOI20_mushrooms) C++17
0 / 100
1 ms 600 KB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

const int B = 100;

int count_mushrooms(int n) {
	if(n<=B){
		int ans = 1;
		for(int i = 1;i<n;i++){
			int re = use_machine(vector<int>({0,i}));
			if(!re)ans++;
		}
		return ans;
	}
	vector<int> v[2];
	v[0].push_back(0);
	int nxt = 1;
	for(int i = 1;max(v[0].size(),v[1].size())<B;i++){
		int re = use_machine(vector<int>({i*2-1,0,i*2}));
		if(re == 0){
			v[0].push_back(i*2-1);
			v[0].push_back(i*2);
		}
		else if(re == 2){
			v[1].push_back(i*2-1);
			v[1].push_back(i*2);
		}
		else{
			re = use_machine(vector<int>({0,i*2-1}));
			if(re == 0){
				v[0].push_back(i*2-1);
				v[1].push_back(i*2);
			}
			else{
				v[1].push_back(i*2-1);
				v[0].push_back(i*2);
			}
		}
		nxt = i*2+1;
	}
	int dir = (v[0].size()<v[1].size());
	int cnt[2] = {v[0].size(),v[1].size()};
	for(int i = nxt;i<n;i+=v[dir].size()+1){
		vector<int> vv;
		for(int j = i;j<min(n,i+(int)v[dir].size()+1);j++)vv.push_back(j);
		vector<int> req;
		for(int j = 0;j<vv.size();j++){
			req.push_back(v[dir][j]);
			req.push_back(vv[j]);
		}
		int re = use_machine(req);
		if(re&1)re++;
		re>>=1;
		cnt[dir^1] += re;
		cnt[dir] += vv.size()-re;
	}
	return cnt[0];
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:43:25: warning: narrowing conversion of 'v[0].std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   43 |  int cnt[2] = {v[0].size(),v[1].size()};
      |                ~~~~~~~~~^~
mushrooms.cpp:43:37: warning: narrowing conversion of 'v[1].std::vector<int>::size()' from 'std::vector<int>::size_type' {aka 'long unsigned int'} to 'int' [-Wnarrowing]
   43 |  int cnt[2] = {v[0].size(),v[1].size()};
      |                            ~~~~~~~~~^~
mushrooms.cpp:48:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   for(int j = 0;j<vv.size();j++){
      |                 ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 1 ms 600 KB Duplicate value 0 in the query array.
7 Halted 0 ms 0 KB -