Submission #1056727

# Submission time Handle Problem Language Result Execution time Memory
1056727 2024-08-13T10:45:21 Z c2zi6 Counting Mushrooms (IOI20_mushrooms) C++14
0 / 100
8 ms 452 KB
#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 use_machine(int l, int r) {
    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

        /*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;
    };

    VI dif(n+1);
    int L = 0;
    while (L < n) {
        L = binsearch(L, n-1);
        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;*/

    int ret = 0;
    for (int x : ans) ret += !x;
	return ret;
}

# 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 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Partially correct 3 ms 452 KB Output is partially correct
6 Incorrect 8 ms 344 KB Too many total array sizes as queries.
7 Halted 0 ms 0 KB -