Submission #825496

#TimeUsernameProblemLanguageResultExecution timeMemory
825496benjaminkleynCounting Mushrooms (IOI20_mushrooms)C++17
92.62 / 100
7 ms348 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

int count_mushrooms(int n)
{
    vector<int> A(1, 0), B;

    int i = 1;
    for (; i < 3 && i < n; i++)
        if (use_machine({0, i}))
            B.push_back(i);
        else
            A.push_back(i);

    int k = 80;
    if (A.size() >= B.size())
    {
        for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
        {
            int x = use_machine({A[0], i, A[1], i+1});

            if (x & 1)
                B.push_back(i+1);
            else
                A.push_back(i+1);

            if (x & 2)
                B.push_back(i);
            else
                A.push_back(i);
        }
    }
    else
    {
        for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
        {
            int x = use_machine({B[0], i, B[1], i+1});

            if (x & 1)
                A.push_back(i+1);
            else
                B.push_back(i+1);

            if (x & 2)
                A.push_back(i);
            else
                B.push_back(i);
        }
    }

    int cnt = A.size();
    while (i < n)
    {
        vector<int> query;
        if (A.size() >= B.size())
        {
            for (int j : A)
            {
                query.push_back(j);
                query.push_back(i++);
                if (i >= n)
                    break;
            }
            int x = use_machine(query);
            cnt += query.size() / 2 - (x + 1) / 2;
            if (x % 2)
                B.push_back(query.back());
            else
                A.push_back(query.back());
        }
        else
        {
            for (int j : B)
            {
                query.push_back(j);
                query.push_back(i++);
                if (i >= n)
                    break;
            }
            int x = use_machine(query);
            cnt += (x + 1) / 2;
            if (x % 2)
                A.push_back(query.back());
            else
                B.push_back(query.back());
        }
    }
    return cnt;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:19:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
      |                             ~~~~~~~~~^~~
mushrooms.cpp:19:54: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |         for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
      |                                             ~~~~~~~~~^~~
mushrooms.cpp:36:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
      |                             ~~~~~~~~~^~~
mushrooms.cpp:36:54: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   36 |         for (; i + 1 < n && A.size() < k && B.size() < k; i += 2)
      |                                             ~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...