# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
960657 | 2024-04-10T20:06:33 Z | MarwenElarbi | 커다란 상품 (IOI17_prize) | C++17 | 0 ms | 0 KB |
#include <bits/stdc++.h> #include "prize.h" using namespace std; std::vector<int> ask(int i); int find_best(int n){ int bg=0; int cnt=0; /*for (int i = 0; i < min(480,n); ++i) { vector<int> cur=ask(i); if(cur[0]==0&&cur[1]==0) return i; if(cnt<=cur[0]+cur[1]){ cnt=max(cnt,cur[0]+cur[1]); bg=i; } }*/ while(true){ //return 0; int l=bg; int r=n; //cout <<l<<endl; vector<int> fir=ask(l); if(fir[0]==0&&fir[1]==0) return l; while(r-l>1){ int mid=(r+l)/2; vector<int> cur=ask(mid); if(cur[0]==0&&cur[1]==0) return mid; if(cur[0]==0) l=mid; else if(cur[0]+cur[1]!=cnt){ r=mid; continue; } else if(cur[1]+fir[0]!=cnt) r=mid; else { l=mid; } } bg=l+1; while(vis[bg]) bg++; fir=ask(bg); if(fir[0]==0&&fir[1]==0) return bg; while(fir[0]+fir[1]!=cnt){ bg++; if(vis[bg]) continue; fir=ask(bg); if(fir[0]==0&&fir[1]==0) return bg; } } return n-1; }