제출 #668121

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

int find_best(int n)
{
    int ans_max = 0;

    for (size_t i = 0; i * i < n; i++)
    {
        vector<int> ans = ask(i);
        ans_max = max(ans_max, ans[0] + ans[1]);

        if (!ans[0] && !ans[1])
            return i;
    }

    int i = -1, found = 0;

    while (1)
    {
        int a = i + 1, b = n - 1;

        while (a < b)
        {
            int mid = (a + b) / 2;
            vector<int> ans = ask(mid);

            if (!ans[0] && !ans[1])
                return mid;

            if (ans[0] + ans[1] == ans_max)
            {
                if (ans[0] == found)
                    a = mid + 1;
                else
                    b = mid;
            }
            else
                b = mid;
        }

        found++;
        i = a;

        vector<int> ans = ask(i);
        if (!ans[0] && !ans[1])
            return i;
    }
}

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

prize.cpp: In function 'int find_best(int)':
prize.cpp:9:30: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    9 |     for (size_t i = 0; i * i < n; i++)
      |                        ~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...