# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1113638 | 2024-11-16T21:56:16 Z | epicci23 | 커다란 상품 (IOI17_prize) | C++17 | 0 ms | 0 KB |
#include "bits/stdc++.h" #include "prize.h" //#define int long long #define all(v) v.begin() , v.end() #define sz(a) (int)a.size() using namespace std; const int N = 2e5 + 5; int mx = -1; vector<bool> mark(N, 0); map<int,vector<int>> dp; vector<int> Ask(int i){ if(dp.count(i)) return dp[i]; return dp[i] = ask(i); } void Learn(int l, int r){ if(l > r) return; if(l == r){ mark[l] = 1; return; } int mid = (l+r)/2 , p = -1; for(int i=0;i<=(r-l+1)/2;i++){ if(mid+i<=r){ vector<int> x = Ask(mid+i); if(x[0]+x[1]==mx){ p=mid+i; break; } Small[mid+i]=1; } if(mid-i>=l){ vector<int> x = Ask(mid-i); if(x[0]+x[1]==mx){ p=mid-i; break; } Small[mid-i]=1; } } if(p == -1) return; if(l < p && Ask(p)[0] - (l > 0 ? Ask(l-1)[0] : 0) ) Learn(l, p - 1); if(p < r && Ask(p)[1] - (r + 1 < n ? Ask(r + 1)[1] : 0) ) Learn(p + 1, r); } int find_best(int n){ for(int i = 0; i < 475 ; i++){ vector<int> x = Ask(i); if(x[0] + x[1] == 0) return i; mx = max(mx, x[0] + x[1]); if(mx > 30) break; } Learn(0, n - 1); for(int i = 0 ; i < n ; i++){ if(Small[i]){ vector<int> x = Ask(i); if(x[0]+x[1] == 0) return i; } } return -23; }