Submission #405414

#TimeUsernameProblemLanguageResultExecution timeMemory
405414dxz05커다란 상품 (IOI17_prize)C++14
20 / 100
137 ms24828 KiB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 5e5 + 3e2;
typedef long long ll;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int foo, hoo;

vector<int> asked_values[MAXN];

int calls_count = 0;

void ASK(int i){
    vector<int> res;
    if (asked_values[i].empty()){
        assert(calls_count < 10000);
        calls_count++;
        res = ask(i);
        //cout << i << ' ' << res.front() << ' ' << res.back() << endl;
    } else res = asked_values[i];

    foo = res.front();
    hoo = res.back();
    asked_values[i] = res;

}

int find_best(int n) {
    int mx = 0;
    for (int i = 0; i < min(n, 500); i++){
        ASK(i);
        if (foo + hoo == 0) return i;
        mx = max(mx, foo + hoo);
    }

    int cur = 0;
	for (int i = 0; i < n; i++){

        int l = i, r = n - 1;
        int nxt = n;

        while (l <= r){
            int m = (l + r) >> 1;
            ASK(m);

            if (foo + hoo == 0) return m;

            if (foo + hoo < mx){
                nxt = m;
                foo -= cur;
                if (foo == 0) break;

                r = m - 1;
                continue;
            }

            if (foo > cur){
                r = m - 1;
            } else l = m + 1;

        }

	}

	assert(false);

	return 0;
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:44:13: warning: variable 'nxt' set but not used [-Wunused-but-set-variable]
   44 |         int nxt = n;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...