Submission #604590

#TimeUsernameProblemLanguageResultExecution timeMemory
604590MherCounting Mushrooms (IOI20_mushrooms)C++14
25 / 100
131 ms336 KiB
#include "mushrooms.h"

using namespace std;

int count_mushrooms(int n) {
	vector<int> cl(n, -1);
	cl[0] = 1;
	if (n == 2)
    {
        return 2 - use_machine({0, 1});
    }
    cl[1] = 1 - use_machine({0, 1});
    cl[2] = 1 - use_machine({0, 2});
    bool t;
    int x, y;
    if (cl[0] == cl[1])
    {
        t = true;
        x = 0;
        y = 1;
    }
    else if (cl[0] == cl[2])
    {
        t = true;
        x = 0;
        y = 2;
    }
    else
    {
        t = false;
        x = 1;
        y = 2;
    }
    for (int i = 3; i < n - 1; i += 2)
    {
        int res = use_machine({x, i, y, i + 1});
        if (res == 0)
        {
            cl[i] = cl[i + 1] = t;
        }
        else if (res == 1)
        {
            cl[i] = t;
            cl[i + 1] = !t;
        }
        else if (res == 2)
        {
            cl[i] = !t;
            cl[i + 1] = t;
        }
        else
        {
            cl[i] = cl[i + 1] = !t;
        }
    }
    if (n % 2 == 0)
    {
        cl[n - 1] = 1 - use_machine({0, n - 1});
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
        ans += cl[i];
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...