#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 sum = 0;
int use_machine(int l, int r) {
sum += r-l+1;
/*cout << "use_machine(" << l << ", " << r << ")" << endl;*/
VI a;
replr(i, l, r) a.pb(i);
return use_machine(a);
}
int count_mushrooms(int n) {
auto binsearch = [&](int L, int R) {
// searching for the first index i
// such that a[i] != a[L] and i is
// in range [L+1, R]
// return R+1 if no such index
setmin(R, n-1);
/*cout << "BINSEARCH(" << L << ", " << R << ")";*/
int l = L, r = R+1;
while (l + 1 < r) {
int m = (l + r) / 2;
if (use_machine(l, m)) r = m;
else l = m;
}
/*cout << " = " << r << endl;*/
return r;
};
int sq = sqrt(n);
VI dif(n+1);
int L = 0;
while (L < n) {
L = binsearch(L, L + sq);
dif[L] = 1;
}
VI ans(n);
int cur = 0;
rep(i, n) {
if (dif[i]) cur = !cur;
ans[i] = cur;
}
/*for (int x : ans) cout << x << " ";*/
/*cout << endl;*/
/*cout << sum << endl;*/
int ret = 0;
for (int x : ans) ret += !x;
return ret;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Partially correct |
1 ms |
344 KB |
Output is partially correct |
6 |
Partially correct |
22 ms |
592 KB |
Output is partially correct |
7 |
Incorrect |
6 ms |
344 KB |
Answer is not correct. |
8 |
Halted |
0 ms |
0 KB |
- |