Submission #927760

#TimeUsernameProblemLanguageResultExecution timeMemory
927760haxormanCounting Mushrooms (IOI20_mushrooms)C++14
10 / 100
65 ms1504 KiB
#include <bits/stdc++.h>
#include "mushrooms.h"
using namespace std;

int count_mushrooms(int n) {
    vector<int> arr = {0};
    for (int i = 0; i < n - 3; i += 3) {
        vector<int> check = {i, i + 1, i + 2, i + 3};
        int res = use_machine(check);

        if (!res) {
            for (int k = 0; k < 3; ++k) {
                arr.push_back(arr[i]);
            }
        }
        else if (res == 3) {
            for (int k = 0; k < 3; ++k) {
                arr.push_back(arr[i] ^ (k&1^1));
            }
        }
        else if (res == 1) {
            check = {i + 1, i + 3, i + 2};
            res = use_machine(check);

            if (!res) {
                for (int k = 0; k < 3; ++k) {
                    arr.push_back(arr[i] ^ 1);
                }
            }
            else if (res == 1) {
                arr.push_back(arr[i]);
                arr.push_back(arr[i] ^ 1);
                arr.push_back(arr[i] ^ 1);
            }
            else {
                arr.push_back(arr[i]);
                arr.push_back(arr[i]);
                arr.push_back(arr[i] ^ 1);
            }
        }
        else {
            check = {i, i + 1, i + 3, i + 2};
            res = use_machine(check);

            if (res == 1) {
                for (int k = 0; k < 3; ++k) {
                    arr.push_back(arr[i] ^ (k&1));
                }
            }
            else if (res == 2) {
                arr.push_back(arr[i] ^ 1);
                arr.push_back(arr[i]);
                arr.push_back(arr[i]);
            }
            else {
                arr.push_back(arr[i] ^ 1);
                arr.push_back(arr[i] ^ 1);
                arr.push_back(arr[i]);
            }
        }
    }
    
    while (arr.size() < n) {
        arr.push_back(arr.back() ^
                     use_machine({(int)arr.size() - 1, (int)arr.size()}));
    }

    int cnt = 0;
    for (int i = 0; i < arr.size(); ++i) {
        cnt += !arr[i];
    }
    return cnt;
}

Compilation message (stderr)

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:18:42: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
   18 |                 arr.push_back(arr[i] ^ (k&1^1));
      |                                         ~^~
mushrooms.cpp:63:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |     while (arr.size() < n) {
      |            ~~~~~~~~~~~^~~
mushrooms.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for (int i = 0; i < arr.size(); ++i) {
      |                     ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...