Submission #432566

#TimeUsernameProblemLanguageResultExecution timeMemory
432566TryMaxCounting Mushrooms (IOI20_mushrooms)C++17
0 / 100
3 ms296 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
#ifdef LOCAL
    #include "stub.cpp"
#endif // LOCAL

#define f first
#define s second
#define pb push_back

using namespace std;

const int N = 2e5 + 10, C = 200;

int a[N];

int small(int n){
    int ans = 1;
    for(int i = 1; i < n; ++i){
        vector<int> x;
        x.pb(i - 1);
        x.pb(i);
        a[i] = a[i - 1] ^ use_machine(x);
        ans += (a[i] == 0);
    }
    return ans;
}

bool ask(int a, int b){
    vector<int> x;
    x.pb(a), x.pb(b);
    return use_machine(x);
}

int count_mushrooms(int n){
    if(n <= C)
        return small(n);
    a[C - 1] = a[0] ^ ask(0, C - 1);
    int ans = (a[0] == 0) + (a[C - 1] == 0);
    for(int i = 1; i < C - 1 - i; ++i){
        vector<int> x;
        x.pb(i);
        x.pb(i - 1);
        x.pb(C - 1 - i + 1);
        x.pb(C - 1 - i);
        int res = use_machine(x);
        if(a[i - 1] != a[C - 1 - i + 1])
            --res;
        if(res == 0)
            a[i] = a[i - 1], a[C - 1 - i] = a[C - i];
        else if(res == 2)
            a[i] = a[i - 1] ^ 1, a[C - 1 - i] = a[C - 1] ^ 1;
        else{
            if(ask(i, i - 1))
                a[i] = a[i - 1] ^ 1, a[C - 1 - i] = a[C - i];
            else
                a[i] = a[i - 1], a[C - 1 - i] = a[C - i] ^ 1;
        }
        ans += a[i] + a[C - i - 1];
    }
    for(int i = 1; i <= (n + C - 1) / C; ++i){
        vector<int> x;
        for(int j = 0; j < min(n, C); ++j)
            if(a[j] == 0){
                if(i * C + j >= n)
                    break;
                x.pb(j), x.pb(i * C + j);
            }
        if(!x.empty()){
            int cntb = (use_machine(x) + 1) / 2;
            ans += x.size() / 2 - cntb;
        }
        x.clear();
        for(int j = 0; j < min(n, C); ++j)
            if(a[j] == 1){
                if(i * C + j >= n)
                    break;
                x.pb(j), x.pb(i * C + j);
            }
        if(!x.empty()){
            int cnta = (use_machine(x) + 1) / 2;
            ans += cnta;
        }
    }
    return ans;
}
/*
3
0 1 1

1
2

7
0 1 0 0 0 1 0

3
2

*/
#Verdict Execution timeMemoryGrader output
Fetching results...