제출 #302116

#제출 시각아이디문제언어결과실행 시간메모리
302116dantoh000커다란 상품 (IOI17_prize)C++14
20 / 100
44 ms512 KiB
#include "prize.h" #include <bits/stdc++.h> using namespace std; int mx = 0; int ans = -1; void search(int ll, int lr, int rl, int rr, int cl, int cr, int c); void search(int L, int R, int cl, int cr, int c){ if (L == R){ vector<int> p = ask(L); int CL = p[0], CR = p[1]; if (CL + CR != mx){ /// is special if (CL == 0 && CR == 0) ans = L; } return; } if (L > R) return; int mid = (L+R)/2; search(L, mid, mid+1, R, cl, cr, c); return; } void search(int ll, int lr, int rl, int rr, int cl, int cr, int c){ if (ans != -1 || c == 0) return; int CL, CR; if (ll < 0 || rr < 0 || rl < 0 || lr < 0 || ll > rr) return; //printf("search <%d,%d><%d,%d>, <%d,%d>, %d\n",ll,lr,rl,rr,cl,cr,c); int q = (rr-rl)>(lr-ll)?rl:lr; vector<int> p = ask(q); CL = p[0], CR = p[1]; if (CL + CR != mx){ /// is special if (CL == 0 && CR == 0) { ans = q; return; } else{ if (q == lr){ search(ll, lr-1, rl, rr, cl, cr, c-1); } else if (q == rl){ search(ll, lr, rl+1, rr, cl, cr, c-1); } } return; } CR -= cr; CL -= cl; if (q == lr){ search(ll, lr-1,cl,CR+cr,CL); search(rl, rr,CL+cl,cr,CR); } else{ search(ll, lr,cl,CR+cr,CL); search(rl+1, rr,CL+cl,cr,CR); } } int find_best(int n) { for (int i = 0; i < min(n,231); i++){ vector<int> p = ask(i); //if (p[0] == 0 && p[1] == 0) return i; mx = max(mx,p[0]+p[1]); } int L, R; L = 0, R = n-1; int mid = (L+R)/2; search(L, mid, mid+1, R, 0, 0, mx); assert(ans != -1); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...