Submission #957369

#TimeUsernameProblemLanguageResultExecution timeMemory
95736912345678Counting Mushrooms (IOI20_mushrooms)C++17
0 / 100
23 ms344 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int res, a, b, m, sz;
vector<int> x, y;

int count_mushrooms(int n) {
    if (n<=282)
    {
        for (int i=1; i<n; i++) if (use_machine(vector<int> {0, i})==0) res++;
        return res+1;
    }
    x.push_back(0);
    if (use_machine(vector<int> {0, 1})==0) 
    {
        a=0, b=1, m=0;
        x.push_back(1);
        if (use_machine(vector<int> {1, 2})==0) x.push_back(2);
        else y.push_back(2);
    }
    else if (use_machine(vector<int> {1, 2})==0) a=1, b=2, m=1, y.push_back(1), y.push_back(2);
    else a=0, b=2, m=0, y.push_back(1), x.push_back(2);
    for (int i=3; i<8; i+=2)
    {
        int tmp=use_machine(vector<int> {a, i, b, i+1});
        if (m)
        {
            if (tmp==3) x.push_back(i), x.push_back(i+1);
            else if (tmp==2) x.push_back(i), y.push_back(i+1);
            else if (tmp==1) x.push_back(i+1), y.push_back(i);
            else y.push_back(i), y.push_back(i+1);
        }
        else
        {
            if (tmp==3) y.push_back(i), y.push_back(i+1);
            else if (tmp==2) y.push_back(i), x.push_back(i+1);
            else if (tmp==2) y.push_back(i+1), x.push_back(i);
            else x.push_back(i), x.push_back(i+1);
        }
    }
    res=x.size();
    if (x.size()>=y.size()) m=0, sz=x.size()-1;
    else m=1, sz=y.size()-1;
    /*
    cout<<"debug x : ";
    for (auto z:x) cout<<z<<' ';
    cout<<'\n';
    cout<<"debug y : ";
    for (auto z:y) cout<<z<<' ';
    cout<<'\n';
    */
    for (int i=9; i<n; i+=sz)
    {
        vector<int> qrs;
        int cnt=0;
        for (int j=0; j<sz; j++)
        {
            if (m) qrs.push_back(y[j]);
            else qrs.push_back(x[j]);
            if (i+j<n) qrs.push_back(i+j), cnt++;
        }
        if (m) qrs.push_back(y.back());
        else qrs.push_back(x.back());
        int tmp=use_machine(qrs)/2;
        if (m) res+=tmp;
        else res+=cnt-tmp;
    }
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...