Submission #778879

#TimeUsernameProblemLanguageResultExecution timeMemory
778879kingfran1907The Big Prize (IOI17_prize)C++14
90 / 100
86 ms2888 KiB
#include "prize.h" #include <bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long llint; const int maxn = 2e5+10; int l[maxn], r[maxn]; int out = -1; int maxi = 0; pair<int,int> query(int x) { if (l[x] != -1) return {l[x], r[x]}; vector< int > v = ask(x); l[x] = v[0], r[x] = v[1]; return {l[x], r[x]}; } llint ra() { return (llint)rand() * rand() + rand() + rand(); } void solve(int l, int r) { if (l > r) return; if (out != -1) return; if (query(l).X + query(l).Y == 0) { out = l; return; } if (query(l).X + query(l).Y < maxi) {solve(l + 1, r); return;} if (l == r) return; if (query(r).X + query(r).Y == 0) { out = r; return; } if (query(r).X + query(r).Y < maxi) {solve(l, r - 1); return;} if (query(l).X == query(r).X) return; int mid = (l + r) / 2; solve(l, mid); solve(mid + 1, r); } int find_best(int n) { memset(l, -1, sizeof l); //srand(31337); vector< int > v; for (int i = 0; i < n; i++) v.push_back(i); for (int i = 0; i < n; i++) swap(v[i], v[ra() % n]); for (int i = 0; i < min(400, n); i++) { int x = v[i]; pair<int, int> tr = query(x); if (tr.X + tr.Y == 0) return x; maxi = max(maxi, tr.X + tr.Y); } solve(0, n - 1); assert(out != -1); return out; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...