Submission #36592

#TimeUsernameProblemLanguageResultExecution timeMemory
36592ruhanhabib39The Big Prize (IOI17_prize)C++14
20 / 100
73 ms6968 KiB
#include "prize.h" #include <bits/stdc++.h> // 123 const int MAXN = 2e5; std::vector<int> res[MAXN + 10]; std::pair<int,int> get(int i) { if(!res[i].size()) res[i] = ask(i); return {res[i][0], res[i][1]}; } int sum(int i) { return get(i).first + get(i).second; } int ls = 0; int lowest(int n) { int mx = 0; for(int i = 0; i*i <= n; i++) { mx = std::max(mx, sum(i)); } return mx; } int solve(int lo, int hi, int lc, int cc) { if(cc == 0) return -1; assert(lo <= hi && cc > 0); if(cc == hi-lo+1) { for(int i = lo; i <= hi; i++) { if(sum(i) == 0) return i; } return -1; } int ml = (lo + hi) / 2 + 1, mr = (lo + hi) / 2; int lf; for(int i = 0; i < hi-lo+1; i++) { int q; if(i % 2 == 0) q = --ml; else q = ++mr; if(sum(q) == ls) { if(i % 2 == 0) lf = get(q).first - lc; else lf = get(q).first - lc - (mr - ml); break; } else if(sum(q) == 0) { return q; } } int rr = solve(lo, ml-1, lc, lf); if(rr != -1) return rr; rr = solve(mr+1, hi, lc + (mr - ml) + lf, cc - lf - (mr - ml)); if(rr != -1) return rr; return -1; } int find_best(int n) { ls = lowest(n); return solve(0, n-1, 0, ls); }

Compilation message (stderr)

prize.cpp: In function 'int solve(int, int, int, int)':
prize.cpp:55:14: warning: 'lf' may be used uninitialized in this function [-Wmaybe-uninitialized]
    rr = solve(mr+1, hi, lc + (mr - ml) + lf, cc - lf - (mr - ml));
              ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...