Submission #304850

# Submission time Handle Problem Language Result Execution time Memory
304850 2020-09-22T02:51:49 Z llaki Counting Mushrooms (IOI20_mushrooms) C++17
Compilation error
0 ms 0 KB
#include <math.h>
#include <iostream>
#include <vector>
#include "mushrooms.h"

int count_mushrooms1(int n) {
	if (n <= 226) {
		std::vector<int> m;
		int ans = 1;
		for (int i = 1; i < n; i++) {
			m = {0, i};
			int res = use_machine(m);
			if (res == 0) ans++;
		}
		return ans;
	}
	int k = (int) (sqrt(n / 2));
	std::vector<int> ones, zeroes;
	int known[20001];
	for (int i = 0; i <= 20000; i++) {
		known[i] = 0;
	}
	for (int q = 0; ; q++) {
		if (1 + q * k >= n) break;
		std::vector<int> query;
		query.push_back(0);
		for (int i = 1; i <= k; i++) {
			int num = i + q * k;
			if (num >= n) break;
			query.push_back(num);
		}
		int res = use_machine(query);
		int largest = query[query.size() - 1];
		if (res % 2 == 0) {
			zeroes.push_back(largest);
		} else {
			ones.push_back(largest);
		}
		known[largest] = 1;
	}
	int countZeroes = 1 + zeroes.size();
	std::vector<int> unknown;
	for (int i = 1; i < n; i++) {
		if (known[i] != 1) {
			unknown.push_back(i);
		}
	}
	std::vector<int> indices = (ones.size() > zeroes.size() ? ones : zeroes);
	bool isOne = ones.size() > zeroes.size();
	int s = indices.size();
	for (int i = 0; i < unknown.size(); i++) {
		std::vector<int> query;
		query.push_back(indices[0]);
		int u = 0;
		for (int j = 1; j < s && i + j - 1 < unknown.size(); j++) {
			query.push_back(unknown[i + j - 1]);
			query.push_back(indices[j]);
			u++;
		}
		if (query.size() < 2) break;
		int res = use_machine(query);
		if (isOne) {
			countZeroes += res / 2;
		} else {
			countZeroes += u - res / 2;
		}
		i = i + s - 2;
	}
	return countZeroes;
}

int main() {
	count_mushrooms1(20000);
	return 0;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms1(int)':
mushrooms.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for (int i = 0; i < unknown.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
mushrooms.cpp:55:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for (int j = 1; j < s && i + j - 1 < unknown.size(); j++) {
      |                            ~~~~~~~~~~^~~~~~~~~~~~~~~~
/tmp/ccqo2eDX.o: In function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccBx8xZZ.o:mushrooms.cpp:(.text.startup+0x0): first defined here
/tmp/ccqo2eDX.o: In function `main':
stub.cpp:(.text.startup+0x87): undefined reference to `count_mushrooms(int)'
collect2: error: ld returned 1 exit status