제출 #72829

#제출 시각아이디문제언어결과실행 시간메모리
72829funcsr커다란 상품 (IOI17_prize)C++17
20 / 100
103 ms3816 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) { assert(num >= 0 && left >= 0); if (num == 0) return -1; //cout<<"solve("<<l<<","<<r<<", num="<<num<<")\n"; int mm = (l+r)/2; for (int mid=mm; 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; } for (int mid=mm+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; } return -1; } int find_best(int N) { rep(i, N) cache[i] = P(-1, -1); if (N <= 5000) { rep(i, N) { P ret = query(i); if (ret._1+ret._2 == 0) return i; } abort(); } rep(i, 460) { P ret = query(i); mp = max(mp, ret._1+ret._2); } //cout<<"mp="<<mp<<"\n"; 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...