제출 #637570

#제출 시각아이디문제언어결과실행 시간메모리
637570boris_mihov커다란 상품 (IOI17_prize)C++17
컴파일 에러
0 ms0 KiB
#include "prize.h"
#include <algorithm>
#include <iostream>
#include <cassert>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF  = 1e9;

int ans;
std::vector <int> res;
std::pair <int,int> asked[MAXN];
inline std::pair <int,int> query(int pos)
{
    if (asked[pos].first != -1) return asked[pos];
    res = ask(pos - 1);
    if (res[0] + res[1] == 0) ans = pos;
    return asked[pos] = {res[0], res[1]};
}

int leftCnt;
int rightCnt;
int cntBig;
int binaryCnt;

int binarySearchLeft(int from, int to)
{
    int l = from, r = to, mid;
    while (l < r - 1)
    {
        int mid = (l + r) / 2;
        auto [left, right] = query(mid);
        if (ans != 0) return -1;
        if (left + right != cntBig)
        {
            r = mid;
            continue;
        }

        if (left != leftCnt)
        {
            r = mid;
            continue;
        }

        l = mid;
    }

    assert(r != n+1);
    query(r);
    leftCnt++;
    return r;
}

int binarySearchRight(int from, int to)
{
    int l = from, r = to, mid;
    while (l < r - 1)
    {
        int mid = (l + r) / 2;
        auto [left, right] = query(mid);
        if (ans != 0) return -1;
        if (left + right != cntBig)
        {
            l = mid;
            continue;
        }

        if (right != rightCnt)
        {
            l = mid;
            continue;
        }

        r = mid;
    }

    query(l);
    rightCnt++;
    return l;
}

int find_best(int n) 
{
	srand(6686889);
    std::fill(asked + 1, asked + 1 + n, std::make_pair(-1, -1));
    for (int i = 1 ; i <= 10 ; ++i)
    {
        int rndPos = rand()%n + 1;
        cntBig = std::max(cntBig, query(rndPos).first + query(rndPos).second);
    }

    int l = 0, r = n + 1;
    while (ans == 0 && l < r - 1)
    {
        l = binarySearchLeft(l, r);
        // if (rand()%2 == 0) l = binarySearchLeft(l, r);
        // else               r = binarySearchRight(l, r);
    }

    if (ans == 0 && l != 0) query(l);
    if (ans == 0 && r != n + 1) query(r);
    return ans - 1;
}

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

In file included from /usr/include/c++/10/cassert:44,
                 from prize.cpp:4:
prize.cpp: In function 'int binarySearchLeft(int, int)':
prize.cpp:51:17: error: 'n' was not declared in this scope
   51 |     assert(r != n+1);
      |                 ^
prize.cpp:30:27: warning: unused variable 'mid' [-Wunused-variable]
   30 |     int l = from, r = to, mid;
      |                           ^~~
prize.cpp: In function 'int binarySearchRight(int, int)':
prize.cpp:59:27: warning: unused variable 'mid' [-Wunused-variable]
   59 |     int l = from, r = to, mid;
      |                           ^~~