Submission #1032582

#TimeUsernameProblemLanguageResultExecution timeMemory
1032582sleepntsheepCounting Mushrooms (IOI20_mushrooms)C++17
56.64 / 100
7 ms600 KiB
#include "mushrooms.h"
#include <cassert>

int count_mushrooms(int n) {
    if (n <= 227) {
        int count = 1, cur = 0;
        for (int i = 1; i < n; ++i) {
            cur ^= (use_machine({i - 1, i}));
            count += !cur;
        }
        return count;
    }

	std::vector<int> A = {0}, B;
    int count = 1;

    int X = 200;

	for (int cur = 0, i = 1; i < X; i++) {
        cur ^= use_machine({i - 1, i});
        if (cur == 0)
            ++count, A.push_back(i);
        else
            B.push_back(i);
    }

    int amogus = std::max(A.size(), B.size());
    int chosen = A.size() >= B.size() ? 0 : 1;

    int l = X;
    while (l < n) {
        int r = std::min(n, l + amogus - 1) - 1;

        std::vector<int> m;

        if (0 == chosen) {
            m = {A[0]};
            for (int j = l, k = 1; j <= r; ++j, ++k) {
                m.push_back(j);
                assert(k < A.size());
                m.push_back(A[k]);
            }
            count += (r - l + 1) - use_machine(m) / 2;
        } else {
            m = {B[0]};
            for (int j = l, k = 1; j <= r; ++j, ++k) {
                m.push_back(j);
                assert(k < B.size());
                m.push_back(B[k]);
            }
            count += use_machine(m) / 2;
        }

        l = r + 1;
    }


	return count;
}

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from mushrooms.cpp:2:
mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:40:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |                 assert(k < A.size());
      |                        ~~^~~~~~~~~~
mushrooms.cpp:48:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |                 assert(k < B.size());
      |                        ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...