제출 #1271912

#제출 시각아이디문제언어결과실행 시간메모리
1271912Aviansh커다란 상품 (IOI17_prize)C++20
90 / 100
18 ms404 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; map<int,vector<int>>mp; vector<int>kask(int n){ if(mp.find(n)!=mp.end()){ return mp[n]; } return mp[n]=ask(n); } int find_best(int n) { mp.clear(); int cutoff = 0; int lef = 0; int ind = -1; for(int i = 0; i < min(n,1000); i++) { vector<int> res = ask(i); if(res[0] + res[1] == 0) return i; if(cutoff<res[0]+res[1]) { cutoff=res[0]+res[1]; ind=i; lef=res[0]; } } while(1){ int lo = ind; int hi = min(n-1,lo+1023); while(lo<hi){ int mid = (lo+hi+1)/2; vector<int>res = ask(mid); if(res[0]+res[1]==0){ return mid; } if(res[0]==lef&&res[0]+res[1]==cutoff){ lo=mid; } else{ hi=mid-1; } } ind=lo; while(++ind<n){ vector<int>res = ask(ind); lef=res[0]; if(res[0]+res[1]==cutoff){ break; } if(res[0]+res[1]==0){ return ind; } } if(ind==n){ break; } } return -1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...