Submission #1057076

#TimeUsernameProblemLanguageResultExecution timeMemory
1057076c2zi6버섯 세기 (IOI20_mushrooms)C++14
10 / 100
123 ms436 KiB
#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) {*/
    /*    int ret = binsearch(L, L + sq);*/
    /*    if (ret == L+sq+1) {*/
    /*        L = L + sq;*/
    /*    } else {*/
    /*        L = ret;*/
    /*        dif[ret] = 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;*/
    int ret = 1;
    replr(i, 1, n-1) if (!use_machine({0, i})) ret++;
    return ret;
}



Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:44:10: warning: variable 'binsearch' set but not used [-Wunused-but-set-variable]
   44 |     auto binsearch = [&](int L, int R) {
      |          ^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...