제출 #602121

#제출 시각아이디문제언어결과실행 시간메모리
602121definitelynotmee버섯 세기 (IOI20_mushrooms)C++17
92.62 / 100
10 ms440 KiB
#include "mushrooms.h"
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;

const int initial =165;

int count_mushrooms(int n) {
    if(n <= 3){
        int resp = 1;
        for(int i = 1; i < n; i++)
            resp+=use_machine({0,i})^1;
        return resp;
    }
    vector<int> start(initial,-1);
    start[0] = 1;
    start[1] = use_machine({0,1})^1;
    start[2] = use_machine({0,2})^1;
    int q1 = 0, q2 = 1, qresp = 1;
    if(start[1] != 1){
        if(start[2] != 1){
            q1 = 1, q2 = 2, qresp = 0;
        } else q2 = 2;
    }
    for(int i = 3; i+1 < min(initial,n); i+=2){
        int ret = use_machine({q1,i+1,q2,i});
        for(int j = 0; j < 2; j++){
            if((1<<j)&ret)
                start[i+j] = qresp^1;
            else start[i+j] = qresp;
        }
    }
    if(start[min(initial,n)-1] == -1){
        start[min(initial,n)-1] = use_machine({0,min(initial,n)-1})^1;
    }
    int resp = 0;
    array<vector<int>,2> mush;
    for(int i = 0; i < min(initial,n); i++){
        //cout << start[i] << ' ';
        resp+=start[i];
        mush[start[i]].push_back(i);
    }
    //cout << '\n';

    int id = initial;
    while(id < n){
        int type = mush[0].size() > mush[1].size() ? 0 : 1;
        vector<int> query;
        int ptr = 0, ct = 0;
        while(id < n && ptr < mush[type].size()){
            query.push_back(mush[type][ptr]);
            query.push_back(id);
            ptr++;
            id++;
            ct++;
        }
        int ret = use_machine(query);
        resp+=type ? ct-(ret+1)/2 : (ret+1)/2;
        if(ret&1)
            mush[type^1].push_back(id-1);
        else mush[type].push_back(id-1);
    }
	
	return resp;
}

컴파일 시 표준 에러 (stderr) 메시지

mushrooms.cpp: In function 'int count_mushrooms(int)':
mushrooms.cpp:57:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         while(id < n && ptr < mush[type].size()){
      |                         ~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...