Submission #51017

#TimeUsernameProblemLanguageResultExecution timeMemory
51017FLDutchmanThe Big Prize (IOI17_prize)C++14
100 / 100
68 ms2236 KiB
#include <bits/stdc++.h> #include "prize.h" using namespace std; #define mp make_pair #define pb push_back const int INF = 1000000000; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef long double num; typedef pair<num, num> nn; typedef vector<nn> vnn; typedef vector<num> vn; typedef vector<vn> vvn; vii answers; int maxVal = 0; int N; ii query(int i){ if(answers[i] != mp(-1, -1)) return answers[i]; vi a = ask(i); //cerr << a[0] << " " << a[1] << endl; return answers[i] = mp(a[0], a[1]); } void genQueries(){ // do 711 queries in the shape of a bs queue<ii> bounds; bounds.push(mp(-1, N)); int queriesLeft = 711; while(queriesLeft --){ ii q = bounds.front(); bounds.pop(); int mb = (q.first+q.second)/2; query(mb); maxVal = max(maxVal, answers[mb].first + answers[mb].second); bounds.push(mp(q.first, mb)); bounds.push(mp(mb, q.second)); } } int find_best(int n){ N = n; answers.assign(n, mp(-1, -1)); genQueries(); int betterFound = 0; int lb = -1; int lastLb = -1; while(betterFound < maxVal){ int rb = n; int lb = -1; while(lb + 1 != rb){ int mb = (lb + rb)/2; ii ans = query(mb); if(ans.second >= maxVal - betterFound or mb <= lastLb){ lb = mb; } else { rb = mb; } } //cerr << rb << endl; betterFound++; lb++; lastLb = lb; } for(int i = 0; i < answers.size(); i++){ if(answers[i] == mp(0, 0)) return i; } }

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:73:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < answers.size(); i++){
                    ~~^~~~~~~~~~~~~~~~
prize.cpp:52:9: warning: unused variable 'lb' [-Wunused-variable]
     int lb = -1;
         ^~
prize.cpp:77:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...