제출 #937827

#제출 시각아이디문제언어결과실행 시간메모리
937827Alcabel커다란 상품 (IOI17_prize)C++17
20 / 100
47 ms600 KiB
#include <bits/stdc++.h>
#include "prize.h"
using namespace std;

const int need = 473;

int find_best(int n) {
    int mxcnt = 0;
    vector<int> res;
    int nonmax = 0;
    for (int i = 0; i < min(n, need); ++i) {
        res = ask(i);
        if (res[0] + res[1] == 0) {
            return i;
        }
        if (res[0] + res[1] > mxcnt) {
            mxcnt = res[0] + res[1];
            nonmax = i;
        } else if (res[0] + res[1] < mxcnt) {
            ++nonmax;
        }
    }
    int last = need - 1;
    while (true) {
        int left = last, right = n;
        while (right - left > 1) {
            int mid = left + (right - left) / 2;
            res = ask(mid);
            if (res[0] + res[1] == 0) {
                return mid;
            }
            if (res[0] + res[1] < mxcnt) {
                right = mid;
            } else if (res[0] == nonmax) {
                left = mid;
            } else {
                right = mid;
            }
        }
        assert(right != n);
        last = right;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...