Submission #1197253

#TimeUsernameProblemLanguageResultExecution timeMemory
1197253siriusThe Big Prize (IOI17_prize)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;


int find_best(int n) {
    const int SAMPLE_SIZE = 500;
    map<int, vector<int>> sum_to_indices; 
    vector<pair<int, int>> responses(n, {-1, -1}); 
    
    for (int i = 0; i < min(n, SAMPLE_SIZE); ++i) {
        vector<int> res = ask(i);
        responses[i] = {res[0], res[1]};
        int sum = res[0] + res[1];
        if (sum == 0) return i; 
        sum_to_indices[sum].push_back(i);
    }


    function<int(int, int)> search = [&](int left, int right) -> int {
        if (left > right) return -1;


        for (const auto& [sum, indices] : sum_to_indices) {
            for (int i = 0; i < indices.size(); ++i) {
                for (int j = i + 1; j < indices.size(); ++j) {
                    int idx1 = indices[i], idx2 = indices[j];
                    if (idx1 < left && idx2 > right) {
                        int x = responses[idx1].first;
                        int y = responses[idx2].first;
                        int count_between = y - x;
                        int known_between = 0;
                        for (int k = idx1 + 1; k < idx2; ++k) {
                            if (responses[k].first != -1) {
                                if (responses[k].first + responses[k].second < sum)
                                    ++known_between;
                            }
                        }
                        if (count_between == known_between)
                            return -1; 
                    }
                }
            }
        }

        int mid = (left + right) / 2;
        if (responses[mid].first == -1) {
            vector<int> res = ask(mid);
            responses[mid] = {res[0], res[1]};
            int sum = res[0] + res[1];
            if (sum == 0) return mid; 
            sum_to_indices[sum].push_back(mid);
        }

        int res_left = search(left, mid - 1);
        if (res_left != -1) return res_left;
        return search(mid + 1, right);
    };

    return search(0, n - 1);
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:11:27: error: 'ask' was not declared in this scope
   11 |         vector<int> res = ask(i);
      |                           ^~~
prize.cpp: In lambda function:
prize.cpp:47:31: error: 'ask' was not declared in this scope
   47 |             vector<int> res = ask(mid);
      |                               ^~~