Submission #1029106

# Submission time Handle Problem Language Result Execution time Memory
1029106 2024-07-20T12:28:52 Z 42kangaroo Rarest Insects (IOI22_insects) C++17
0 / 100
1 ms 600 KB
#include "insects.h"
#include "bits/stdc++.h"

using namespace std;

int min_cardinality(int N) {
	int nums = 0;
	vector<int> inside, outside, aIn;
	vector<int> o(N);
	std::iota(o.begin(), o.end(),0);
	random_device dev;
	std::shuffle(o.begin(), o.end(), dev);
	for (int i = 0; i < N; ++i) {
		nums++;
		move_inside(o[i]);
		if (press_button() > 1) {
			if (i == N - 1) {
				aIn.push_back(o[i]);
			} else {
				outside.push_back(o[i]);
				move_outside(o[i]);
			}
		} else {
			if (i == N - 1) return 1;
			inside.push_back(o[i]);
		}
	}
	int k = inside.size();
	int l = 1, r = N / k + 1;
	while (l + 1 < r) {
		int m = (l + r + 1) / 2;
		vector<int> nIn, nOut;
		for (auto e: outside) {
			if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
				nOut.push_back(e);
			} else {
				nums++;
				move_inside(e);
				if (press_button() > m) {
					nOut.push_back(e);
					move_outside(e);
				} else nIn.push_back(e);
			}
		}
		if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
			l = m;
			outside = nOut;
			inside.insert(inside.end(), nIn.begin(), nIn.end());
			inside.insert(inside.end(), aIn.begin(), aIn.end());
			aIn.clear();
		} else {
			r = min(m, (int)(inside.size() + nIn.size() + aIn.size())/k + 1);
			int nM = (l + r + 1) / 2 - l;
			nIn.insert(inside.end(), aIn.begin(), aIn.end());
			aIn.clear();
			for (int i = 0; i < nM && !nIn.empty(); ++i) {
				aIn.push_back(*nIn.begin());
				nIn.erase(nIn.begin());
			}
			for (auto e: nIn) {
				move_outside(e);
			}
			outside = nIn;
		}
	}
	//if ((double)nums/(double)N > 3) return 0;
	return l;
}

Compilation message

insects.cpp: In function 'int min_cardinality(int)':
insects.cpp:34:50: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   34 |    if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
      |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
insects.cpp:45:49: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   45 |   if ((inside.size() + nIn.size() + aIn.size()) == m * k) {
      |       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Runtime error 1 ms 600 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Runtime error 1 ms 600 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 0 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -