/**
* In the name of Allah
* We are nothing and you're everything
**/
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
//#define int long long
const char nl = '\n';
//string s;
//int use_machine(vector<int> x) {
//int cnt = 0;
//for (int i = 1; i < sz(x); ++i)if (s[x[i]] != s[x[i-1]])cnt += 1;
//return cnt;
//}
int count_mushrooms(int n) {
int k = 1, res = 1;
vector<int> a(1), b;
int i = 1;
while (i < n) {
int mn = min(n-i, k);
vector<int> x;
if (sz(a) >= sz(b))
for (int j = 0; j < mn; ++j) {
x.push_back(j+i);
x.push_back(a[j]);
}
else
for (int j = 0; j < mn; ++j) {
x.push_back(j+i);
x.push_back(b[j]);
}
int cnt = use_machine(x);
if (sz(a) >= sz(b))res += mn-(cnt+1)/2;
else res += (cnt+1)/2;
int onki = k;
if (cnt&1) {
if (sz(a) >= sz(b))b.push_back(i);
else a.push_back(i);
k = max(sz(a), sz(b));
}
i += onki;
}
return res;
}
//int main() {
//cin >> s;
//cout << count_mushrooms(sz(s));
//}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |