Submission #796497

#TimeUsernameProblemLanguageResultExecution timeMemory
796497NothingXDThe Big Prize (IOI17_prize)C++17
100 / 100
39 ms1872 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef complex<ld> point; void debug_out(){cerr << endl;} template<typename Head, typename... Tail> void debug_out(Head H, Tail... T){ cerr << H << ' '; debug_out(T...); } #define debug(...) cerr << "(" << #__VA_ARGS__ << "): ", debug_out(__VA_ARGS__) #define F first #define S second #define all(x) x.begin(), x.end() #define MP(x, y) make_pair(x, y) const int maxn = 2e5 + 10; const int sq = 500; int n, a[maxn][2]; bool askq(int x){ if (a[x][0] != -1) return false; vector<int> res = ask(x); a[x][0] = res[0]; a[x][1] = res[1]; return (a[x][0] == 0 && a[x][1] == 0); } int find_best(int _n){ n = _n; memset(a, -1, sizeof a); int mx = 0; vector<pair<pii,pii>> q; q.push_back({{0, n}, {0, 0}}); while(!q.empty()){ int l = q.back().F.F, r = q.back().F.S; int cntl = q.back().S.F, cntr = q.back().S.S; //debug(l, r, cntl, cntr); q.pop_back(); if (l + 1 == r){ if (askq(l)) return l; continue; } int mid = (l + r) >> 1; bool flg = false; int x = mid; while(x != r){ if (askq(x)) return x; if (a[x][0] + a[x][1] > mx){ mx = a[x][0] + a[x][1]; q.clear(); q.push_back({{0, n}, {0, 0}}); flg = true; break; } if (a[x][0] + a[x][1] < mx){ x++; continue; } flg = true; int L = a[x][0] - cntl - (x-mid); int R = a[x][1] - cntr; if (L > 0){ q.push_back({{l, mid}, {cntl, a[x][1] + (x-mid)}}); } if (R > 0){ q.push_back({{x+1, r}, {a[x][0], cntr}}); } break; } if (!flg){ if (mx - cntl - cntr - (x-mid) > 0) q.push_back({{l, mid}, {cntl, cntr + (x-mid)}}); } } assert(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...