Submission #834338

#TimeUsernameProblemLanguageResultExecution timeMemory
834338finn__Counting Mushrooms (IOI20_mushrooms)C++17
92.62 / 100
13 ms356 KiB
#include <bits/stdc++.h>

#include "mushrooms.h"

using namespace std;

constexpr size_t M = 80;

int count_mushrooms(int n)
{
    vector<int> a_indices = {0}, b_indices;

    (use_machine({0, 1}) ? b_indices : a_indices).push_back(1);
    if (n == 2)
        return a_indices.size();
    (use_machine({0, 2}) ? b_indices : a_indices).push_back(2);

    int last_known = 2;

    // Search for at least M A or B.
    for (int i = last_known + 1; i + 1 < n; i += 2)
    {
        bool flag = a_indices.size() >= 2;
        int x = use_machine({flag ? a_indices[0] : b_indices[0], i,
                             flag ? a_indices[1] : b_indices[1], i + 1});
        last_known = i + 1;
        if ((bool)(x & 2) ^ !flag)
            b_indices.push_back(i);
        else
            a_indices.push_back(i);

        if ((bool)(x & 1) ^ !flag)
            b_indices.push_back(i + 1);
        else
            a_indices.push_back(i + 1);

        if (a_indices.size() >= M || b_indices.size() >= M)
            break;
    }

    int num_a = a_indices.size();

    for (int i = last_known + 1; i < n;)
    {
        vector<int> &r = a_indices.size() > b_indices.size() ? a_indices : b_indices;
        size_t m = r.size();
        bool flag = a_indices.size() > b_indices.size();
        vector<int> v;
        for (int j = 0; j < m && i + j < n; ++j)
        {
            v.push_back(r[j]);
            v.push_back(i + j);
        }

        int x = use_machine(v);
        num_a += flag ? v.size() / 2 - (x + 1) / 2 : (x + 1) / 2;
        (((x & 1) ^ flag) ? a_indices : b_indices).push_back(i + m - 1);
        i += m;
    }

    return num_a;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:49:27: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for (int j = 0; j < m && i + j < n; ++j)
      |                         ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...