Submission #769695

#TimeUsernameProblemLanguageResultExecution timeMemory
769695marvinthangCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
1 ms208 KiB
/*************************************
*    author: marvinthang             *
*    created: 30.06.2023 10:50:39    *
*************************************/

#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

#define                  fi  first
#define                  se  second
#define                left  ___left
#define               right  ___right
#define                TIME  (1.0 * clock() / CLOCKS_PER_SEC)
#define             MASK(i)  (1LL << (i))
#define           BIT(x, i)  ((x) >> (i) & 1)
#define  __builtin_popcount  __builtin_popcountll
#define              ALL(v)  (v).begin(), (v).end()
#define           REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define          REPD(i, n)  for (int i = (n); i--; )
#define        FOR(i, a, b)  for (int i = (a), _b = (b); i < _b; ++i) 
#define       FORD(i, b, a)  for (int i = (b), _a = (a); --i >= _a; ) 
#define       FORE(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define      FORDE(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i) 
#define        scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define       print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#ifdef LOCAL
    #include "debug.h"
#else
    #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
    #define DB(...) 23
    #define db(...) 23
    #define debug(...) 23
#endif

template <class U, class V> scan_op(pair <U, V>)  { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>)  { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>)  { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")";  else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }

// end of template

int count_mushrooms(int n) {
	vector <vector <int>> pos(2);
	pos[0].push_back(0);
	pos[use_machine(vector<int>{0, 1})].push_back(1);
	if (n == 2) return pos[0].size();
	pos[use_machine(vector<int>{0, 2})].push_back(2);
	int i = 3;
	while (i + 1 < n && max(pos[0].size(), pos[1].size()) < 80) {
		bool p = pos[0].size() < pos[1].size();
		vector <int> v;
		REP(j, 2) {
			v.push_back(i + j);
			v.push_back(pos[p][j]);
		}
		int cur = use_machine(v);
		pos[p ^ (cur >> 1)].push_back(i);
		pos[p ^ (cur & 1)].push_back(i);
		i += 2;
	}
	int cnt_0 = pos[0].size();
	for (; i < n; ) {
		bool p = pos[0].size() < pos[1].size();
		vector <int> v;
		int j = 0;
		for (; j < min(n - i, (int) pos[p].size()); ++j) {
			v.push_back(i + j);
			v.push_back(pos[p][j]);
		}
		int cur = use_machine(v);
		cnt_0 += p ? (cur + 1) / 2 : j - (cur + 1) / 2;
		pos[p ^ (cur & 1)].push_back(i);
		i += j;
	}
	return cnt_0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...