Submission #72822

#TimeUsernameProblemLanguageResultExecution timeMemory
72822funcsrThe Big Prize (IOI17_prize)C++17
20 / 100
71 ms3792 KiB
#include "prize.h" #include <iostream> #include <vector> #include <algorithm> #include <queue> #include <cmath> #include <cassert> #include <random> using namespace std; #define rep(i,n)for (int i=0; i<(n); i++) #define all(x) (x).begin(), (x).end() #define pb push_back #define _1 first #define _2 second #define INF 1145141919 typedef pair<int, int> P; mt19937 mt_rand(114514); int mp = 0; P cache[200000]; int Q=0; P query(int x) { if (cache[x] != P(-1, -1)) return cache[x]; Q++; assert(Q<=10000); //if(Q%100==0)cout<<"Q="<<Q<<"\n"; vector<int> ret = ask(x); return cache[x] = {ret[0], ret[1]}; } int solve(int l, int r, int num, int left) { if (num <= 0) return -1; //cout<<"solve("<<l<<","<<r<<", num="<<num<<")\n"; for (int mid=(l+r)/2+1; mid<=r; mid++) { P ret = query(mid); if (ret._1+ret._2 == 0) return mid; if (ret._1+ret._2 != mp) continue; if (mid > l) { int o = solve(l, mid-1, ret._1-left, left); if (o != -1) return o; } if (mid < r) { int o = solve(mid+1, r, num-(ret._1-left), ret._1); if (o != -1) return o; } return -1; } for (int mid=(l+r)/2; mid>=l; mid--) { P ret = query(mid); if (ret._1+ret._2 == 0) return mid; if (ret._1+ret._2 != mp) continue; if (mid > l) { int o = solve(l, mid-1, ret._1-left, left); if (o != -1) return o; } if (mid < r) { int o = solve(mid+1, r, num-(ret._1-left), ret._1); if (o != -1) return o; } return -1; } return -1; } int find_best(int N) { rep(i, N) cache[i] = P(-1, -1); rep(i, 30) { P ret = query(mt_rand()%N); mp = max(mp, ret._1+ret._2); } //cout<<"mp="<<mp<<"\n"; assert(mp < 500); int r = solve(0, N-1, mp, 0); assert(r != -1); return r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...