Submission #448268

#TimeUsernameProblemLanguageResultExecution timeMemory
448268dxz05Counting Mushrooms (IOI20_mushrooms)C++14
56.93 / 100
13 ms328 KiB
#include "mushrooms.h"
#include <bits/stdc++.h>

using namespace std;

int count_mushrooms(int n) {
    vector<int> vec;
    int k = 94;

    vector<int> A = {0}, B;
    for (int i = 1; i <= min(n - 1, 2 * k - 2); i++){
	    if (use_machine({0, i})) B.push_back(i); else
	        A.push_back(i);
	}

    int beg = 2 * k - 1;

    k = max(A.size(), B.size());

    bool ok = A.size() >= B.size();

    int ans = A.size();
    for (int i = beg; i < n; i++){
        vec.clear();
        for (int j = i; j < min(n, i + k); j++){
            vec.push_back(ok ? A[j - i] : B[j - i]);
            vec.push_back(j);
        }
        i += k - 1;

        int res = use_machine(vec);
        if (ok){
            ans += vec.size() / 2 - (res + 1) / 2;
        } else {
            ans += (res + 1) / 2;
        }
    }

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...