Submission #1055591

# Submission time Handle Problem Language Result Execution time Memory
1055591 2024-08-12T23:14:00 Z Trent Counting Mushrooms (IOI20_mushrooms) C++17
0 / 100
1 ms 344 KB
#include "mushrooms.h"
#include "bits/stdc++.h"
using namespace std;
#define forR(i, x) for(int i = 0; i < (x); ++i)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<bool> vb;
typedef long long ll;
typedef vector<ll> vll;
typedef set<int> si;

int count_mushrooms(int n) {
	int IVL = 100;
	vi chk;
	for(int i = 0; i < n; i += IVL) chk.push_back(i);
	if(chk.back() < n-1) chk.push_back(n-1);
	vi ty(chk.size());
	ty[0] = 0;
	REP(i, 1, chk.size()) {
		vi tst = {0, chk[i]};
		ty[i] = use_machine(tst) == 0 ? 0 : 1;
	}

	vi ac, bc;
	forR(i, chk.size()) {
		if(ty[i] == 0) ac.push_back(chk[i]);
		else bc.push_back(chk[i]);
	}
	vb usd(n, false);
	for(int i : chk) usd[i] = true;
	vector<si> ai(ac.size()), bi(bc.size());
	forR(i, ac.size() - 1) for(int j = ac[i] + 1; j < ac[i+1]; ++j) if(!usd[j]) ai[i].insert(j);
	forR(i, bc.size() - 1) for(int j = bc[i] + 1; j < bc[i+1]; ++j) if(!usd[j]) bi[i].insert(j);
	vi ain(n), bin(n);
	forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
	forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;

	si ane, bne;
	forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
	forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
	int tot = ac.size();
	while(!ane.empty() || !bne.empty()){
		si qus;
		if(ane.size() >= bne.size()) {
			for(int i : ane) {
				qus.insert(ac[i]);
				qus.insert(ac[i+1]);
				qus.insert(*ai[i].begin());
			}
			vi qu;
			for(int i : qus) qu.push_back(i);
			int res = use_machine(qu);
			cerr << qu.size() << ' ' << res << '\n';
			tot += ane.size() - res / 2;
		} else {
			for(int i : bne) {
				qus.insert(bc[i]);
				qus.insert(bc[i+1]);
				qus.insert(*bi[i].begin());
			}
			vi qu;
			for(int i : qus) qu.push_back(i);
			int res = use_machine(qu);
			cerr << qu.size() << ' ' << res << '\n';
			tot += res / 2;
		}
		for(int i : qus) {
			if(!usd[i]) {
				usd[i] = true;
				ai[ain[i]].erase(i);
				if(ai[ain[i]].empty()) ane.erase(ain[i]);
				bi[bin[i]].erase(i);
				if(bi[bin[i]].empty()) bne.erase(bin[i]);
			}
		}
	}
	forR(i, n) if(!usd[i]) {
		tot += use_machine({0, i}) == 0 ? 1 : 0;
	}
	return tot;
}

Compilation message

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:5:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define REP(i, a, b) for(int i = (a); i < (b); ++i)
      |                                         ^
mushrooms.cpp:20:2: note: in expansion of macro 'REP'
   20 |  REP(i, 1, chk.size()) {
      |  ^~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:26:2: note: in expansion of macro 'forR'
   26 |  forR(i, chk.size()) {
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:33:2: note: in expansion of macro 'forR'
   33 |  forR(i, ac.size() - 1) for(int j = ac[i] + 1; j < ac[i+1]; ++j) if(!usd[j]) ai[i].insert(j);
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:34:2: note: in expansion of macro 'forR'
   34 |  forR(i, bc.size() - 1) for(int j = bc[i] + 1; j < bc[i+1]; ++j) if(!usd[j]) bi[i].insert(j);
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:36:2: note: in expansion of macro 'forR'
   36 |  forR(i, ai.size()) for(int j : ai[i]) ain[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:37:2: note: in expansion of macro 'forR'
   37 |  forR(i, bi.size()) for(int j : bi[i]) bin[j] = i;
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:40:2: note: in expansion of macro 'forR'
   40 |  forR(i, ai.size()) if(!ai[i].empty()) ane.insert(i);
      |  ^~~~
mushrooms.cpp:4:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::set<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define forR(i, x) for(int i = 0; i < (x); ++i)
      |                                     ^
mushrooms.cpp:41:2: note: in expansion of macro 'forR'
   41 |  forR(i, bi.size()) if(!bi[i].empty()) bne.insert(i);
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Runtime error 1 ms 344 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -