#include <bits/stdc++.h>
#include "mushrooms.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define N 100005
#define PB push_back
#define sz(x) int(x.size())
#define F first
#define M ll(1e9 + 7)
#define S second
#define all(x) x.begin(), x.end()
#define endl '\n'
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
//typedef tree <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int val[N], kol, sum = 0;
//int use_machine(vector <int> &pr)
//{
// sum += sz(pr);
//
// if (sz(pr) < 2) exit(0);
//
// kol++;
//
// int ans = 0;
//
// for (int i = 1; i < sz(pr); i++)
// if (val[pr[i]] != val[pr[i - 1]]) ans++;
//
// return ans;
//}
int ask(vector <int> &m) { return use_machine(m);}
int ask(set <int> &se) {vector <int> m; m.clear(); for (auto it : se) m.PB(it); return use_machine(m);}
ll mlt(ll x, ll y) {return (x * y) % M;}
ll sm(ll x, ll y) {return (x + y) % M;}
int NEED = 20, nr;
vector <int> tr;
int es_minus_3(vector <int> &pr, set <int> &se)
{
int ans = sz(pr);
while (sz(se) > 0)
{
int i = 0;
vector <int> m; m.clear();
while (i + 1 < sz(pr) && sz(se) > 0)
{
m.PB(pr[i++]);
m.PB(*se.begin());
se.erase(se.begin());
}
m.PB(pr[i++]);
int koler = (sz(m) / 2) - (ask(m) / 2);
ans += koler;
}
return ans;
}
void fnd(set <int> &se)
{
if (sz(tr) >= NEED) return;
if (sz(se) == 2)
{
vector <int> m; m.clear(); m.PB(0); m.PB(*se.begin());
if (ask(m) == 0)
{
tr.PB(*se.begin());
se.erase(se.begin());
}
else
{
tr.PB(*se.rbegin());
se.erase(*se.rbegin());
}
return;
}
if (sz(se) == 3)
{
vector <int> m; m.clear(); m.PB(*se.begin()); se.erase(se.begin()); m.PB(*se.begin()); se.erase(se.begin());
if (ask(m) == 0)
{
vector <int> pl; pl.clear();
pl.PB(0); pl.PB(*se.begin());
if (ask(pl) == 0) {tr.PB(*se.begin()); se.erase(*se.begin()); se.insert(m[0]); se.insert(m[1]); return;}
else {tr.PB(m[0]); tr.PB(m[1]); return;}
}
set <int> st; st.clear();
st.insert(m[0]); st.insert(m[1]);
fnd(st);
for (auto it : st) se.insert(it);
return;
}
if (nr >= 5000)
{
set <int> st; st.clear();
int nm = sz(se) / 2;
while (sz(st) < nm) {st.insert(*se.begin()); se.erase(se.begin());}
if (sz(st) > 5 || sz(se) > 5)
{
fnd(st);
fnd(se);
}
else
{
if (ask(st)) fnd(st);
else if (ask(se)) fnd(se);
else
{
set <int> str = st;
for (auto it : se) str.insert(it);
if (ask(str))
{
set <int> prr; prr.clear();
prr.insert(*st.rbegin());
prr.insert(0);
if (ask(prr)) {tr.PB(*st.rbegin()); st.erase(*st.rbegin());} else {tr.PB(*se.begin()); se.erase(se.begin());}
}
}
}
for (auto it : st) se.insert(it);
}
else
{
set <int> st; st.clear();
int nm = sz(se) / 2;
while (sz(st) < nm) {st.insert(*se.begin()); se.erase(se.begin());}
if (ask(st) != 0) fnd(st);
else if (ask(se) != 0) fnd(se);
else
{
int l = *st.rbegin(), r = *se.begin();
vector <int> m = {l, 0};
if (ask(m) == 0) {tr.PB(l); st.erase(l);}
else {tr.PB(r); se.erase(r);}
}
for (auto it : st) se.insert(it);
}
}
int count_mushrooms(int n)
{
nr = n;
tr.PB(0);
vector <int> m; m.clear();
m.PB(0);
set <int> se; se.clear();
for (int i = 1; i < n; i++) se.insert(i);
int i = 1;
while (i < n && sz(tr) < NEED)
{
m.PB(i);
int val = ask(m);
m.pop_back();
if (val == 1) break;
se.erase(i);
tr.PB(i++);
}
while (sz(tr) < NEED && sz(se) > 0)
{
if (sz(se) == 1)
{
vector <int> m = {0, *se.begin()};
if (ask(m) == 0) tr.PB(*se.begin());
return sz(tr);
}
if (ask(se) == 0) return sz(tr);
fnd(se);
}
return es_minus_3(tr, se);
}
//int main()
//{
// iostream::sync_with_stdio(0); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//
// freopen("1.in", "r", stdin); //freopen("fcolor.out", "w", stdout);
//
// int n;
//
// cin >> n;
//
// int num = 0;
//
// for (int i = 0; i < n; i++) {cin >> val[i]; if (val[i] == 0) num++;}
//
// cout << num << endl;
//
// cout << count_mushrooms(n) << endl;
//
// cout << kol << " " << sum << endl;
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Partially correct |
22 ms |
520 KB |
Output is partially correct |
7 |
Partially correct |
20 ms |
1280 KB |
Output is partially correct |
8 |
Partially correct |
19 ms |
1280 KB |
Output is partially correct |
9 |
Partially correct |
29 ms |
1780 KB |
Output is partially correct |
10 |
Incorrect |
29 ms |
1788 KB |
Answer is not correct. |
11 |
Halted |
0 ms |
0 KB |
- |