답안 #1056766

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1056766 2024-08-13T11:00:43 Z c2zi6 버섯 세기 (IOI20_mushrooms) C++14
0 / 100
23 ms 600 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 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) {
            /*cout << "SO THERE IS A CHANGE AT INDEX " << ret << endl;*/
            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;
}







# 결과 실행 시간 메모리 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 1 ms 344 KB Output is correct
5 Partially correct 1 ms 344 KB Output is partially correct
6 Partially correct 20 ms 344 KB Output is partially correct
7 Partially correct 10 ms 600 KB Output is partially correct
8 Partially correct 13 ms 504 KB Output is partially correct
9 Incorrect 23 ms 344 KB Too many total array sizes as queries.
10 Halted 0 ms 0 KB -