제출 #588343

#제출 시각아이디문제언어결과실행 시간메모리
588343supercatex버섯 세기 (IOI20_mushrooms)C++14
0 / 100
1 ms208 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>
using namespace std;

int check_1(int x1)
{
    return use_machine(vector<int>{0, x1});
}

void check_2(int x1, int x2, vector<int> &a, vector<int> &b)
{
    int x = use_machine(vector<int>{x1, a[0], x2});
    if (x == 0) {
        a.push_back(x1);
        a.push_back(x2);
    } else if (x == 2) {
        b.push_back(x1);
        b.push_back(x2);
    } else {
        if (check_1(x1) == 0) {
            a.push_back(x1);
            b.push_back(x2);
        } else {
            a.push_back(x2);
            b.push_back(x1);
        }
    }
}

void check_3(int x1, int x2, int x3, vector<int> &a, vector<int> &b)
{
    if (b.size() > 0) {
        int x = use_machine(vector<int>{x1, a[0], x2, b[0], x3});
        if (x == 1) {
            a.push_back(x1);
            b.push_back(x3);
            if (check_1(x2) == 0) {
                a.push_back(x2);
            } else {
                b.push_back(x2);
            }
        } else if (x == 2) {
            if (check_1(x1) == 0) {
                a.push_back(x1);
                b.push_back(x2);
                a.push_back(x3);
            } else {
                b.push_back(x1);
                a.push_back(x2);
                b.push_back(x3);
            }
        } else if (x == 3) {
            b.push_back(x1);
            a.push_back(x3);
            if (check_1(x2) == 0) {
                a.push_back(x2);
            } else {
                b.push_back(x2);
            }
        }
    } else {
        int x = use_machine(vector<int>{x1, a[0], x2, a[1], x3});
        if (x == 0) {
            a.push_back(x1);
            a.push_back(x2);
            a.push_back(x3);
        } else if (x == 1) {
            if (check_1(x1) == 0) {
                a.push_back(x1);
                a.push_back(x2);
                b.push_back(x3);
            } else {
                b.push_back(x1);
                a.push_back(x2);
                a.push_back(x3);
            }
        } else if (x == 2) {
            if (check_1(x1) == 0) {
                a.push_back(x1);
                b.push_back(x2);
                a.push_back(x3);
            } else {
                b.push_back(x1);
                a.push_back(x2);
                b.push_back(x3);
            }
        } else if (x == 3) {
            if (check_1(x1) == 0) {
                a.push_back(x1);
                b.push_back(x2);
                b.push_back(x3);
            } else {
                b.push_back(x1);
                b.push_back(x2);
                a.push_back(x3);
            }
        } else if (x == 4) {
            b.push_back(x1);
            b.push_back(x2);
            b.push_back(x3);
        }
    }
}

int count_mushrooms(int n)
{
    vector<int> a = {0}, b;
    check_2(1, 2, a, b);

    int i = 3;
    while (i + 2 < n) {
        check_3(i, i + 1, i + 2, a, b);
        i = i + 3;
    }
    if (n % 3 == 2) {
        check_2(n - 1, n - 2, a, b);
    } else if (n % 3 == 1) {
        if (check_1(n - 1) == 0)
            a.push_back(n - 1);
        else
            b.push_back(n - 1);
    }
    return a.size();
}
#Verdict Execution timeMemoryGrader output
Fetching results...