Submission #609884

#TimeUsernameProblemLanguageResultExecution timeMemory
609884KoDCounting Mushrooms (IOI20_mushrooms)C++17
92.62 / 100
10 ms464 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using std::array;
using std::pair;
using std::tuple;
using std::vector;

constexpr int K = 80;

int count_mushrooms(int n) {
    vector<char> color(n);
    array<vector<int>, 2> list = {};
    list[0].push_back(0);
    int k = 1;
    while (k < n and (int)std::max(list[0].size(), list[1].size()) < K) {
        if (k + 1 == n or (list[0].size() <= 1 and list[1].size() <= 1)) {
            color[k] = use_machine({0, k});
            list[color[k]].push_back(k);
            k += 1;
        } else {
            if (list[0].size() >= 2) {
                const int tmp = use_machine({list[0][0], k, list[0][1], k + 1});
                color[k] = tmp / 2;
                color[k + 1] = tmp % 2;
            } else {
                const int tmp = use_machine({list[1][0], k, list[1][1], k + 1});
                color[k] = 1 - tmp / 2;
                color[k + 1] = 1 - tmp % 2;
            }
            list[color[k]].push_back(k);
            list[color[k + 1]].push_back(k + 1);
            k += 2;
        }
    }
    int ret = std::count(color.begin(), color.begin() + k, 0);
    while (k < n) {
        const int fixed = list[0].size() >= list[1].size() ? 0 : 1;
        const int l = k;
        const int r = std::min(n, k + (int)list[fixed].size());
        k = r;
        vector<int> vec;
        for (int i = l; i < r; ++i) {
            vec.push_back(list[fixed][i - l]);
            vec.push_back(i);
        }
        const int query = use_machine(vec);
        if (fixed == 0) {
            ret += (r - l) - (query + 1) / 2;
            list[query % 2].push_back(r - 1);
        } else {
            ret += (query + 1) / 2;
            list[1 - query % 2].push_back(r - 1);
        }
    }
    return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...