#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "mushrooms.h"
int count_mushrooms(int n) {
VI mek, zro;
zro.pb(0);
int cnt0 = 1;
int last = 1;
if (n >= 10) {
if (!use_machine({0, 1})) {
zro.pb(1);
last++;
cnt0++;
} else {
mek.pb(1);
last++;
if (!use_machine({0, 2})) {
zro.pb(2);
last++;
cnt0++;
} else {
mek.pb(2);
last++;
}
}
rep(_, 100) {
if (mek.size() >= zro.size()) {
int ret = use_machine({mek[0], last++, mek[1], last++});
if (ret == 0) {
mek.pb(last-2);
mek.pb(last-1);
} else if (ret == 1) {
cnt0 += 1;
mek.pb(last-2);
zro.pb(last-1);
} else if (ret == 2) {
cnt0 += 1;
zro.pb(last-2);
mek.pb(last-1);
} else {
cnt0 += 2;
zro.pb(last-2);
zro.pb(last-1);
}
} else {
int ret = use_machine({zro[0], last++, zro[1], last++});
if (ret == 0) {
cnt0 += 2;
zro.pb(last-2);
zro.pb(last-1);
} else if (ret == 1) {
cnt0 += 1;
zro.pb(last-2);
mek.pb(last-1);
} else if (ret == 2) {
cnt0 += 1;
mek.pb(last-2);
zro.pb(last-1);
} else {
mek.pb(last-2);
mek.pb(last-1);
}
}
}
}
while (last < n) {
VI qr;
for (int x : (mek.size() > zro.size() ? mek : zro)) {
qr.pb(x);
qr.pb(last++);
if (last >= n) break;
}
int ret = use_machine(qr);
int urish = (ret+1)/2;
if (mek.size() > zro.size()) {
cnt0 += urish;
if (ret & 1) zro.pb(last-1);
else mek.pb(last-1);
} else {
cnt0 += qr.size()/2 - urish;
if (ret & 1) mek.pb(last-1);
else zro.pb(last-1);
}
}
return cnt0;
}
# |
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 |
Incorrect |
0 ms |
344 KB |
Invalid value 10 in the query array. |
4 |
Halted |
0 ms |
0 KB |
- |