제출 #554251

#제출 시각아이디문제언어결과실행 시간메모리
554251GurbanGap (APIO16_gap)C++17
42.76 / 100
46 ms2240 KiB
#include "bits/stdc++.h" #include "gap.h" using namespace std; using ll = long long; long long findGap(int T, int N) { ll cep,sag; MinMax(1,(ll)1e18,&cep,&sag); if(T == 1){ vector<ll>v; v.push_back(cep); v.push_back(sag); while(cep < sag - 1 and (int)v.size() < N){ ll cp,sg; MinMax(cep+1,sag-1,&cp,&sg); if(cp != -1){ v.push_back(cp); if(cp == sg) break; v.push_back(sg); cep = cp; sag = sg; } } sort(v.begin(),v.end()); ll ans = 0; for(int i = 1;i < (int)v.size();i++) ans = max(ans,v[i] - v[i - 1]); return ans; } ll now = cep,ans = 1; while(now < sag){ ll nwa,nwb; if(now + ans + 1 > sag) break; MinMax(now + 1,now + ans + 1,&nwa,&nwb); if(nwa != -1){ ans = max(ans,nwa - now); now = nwb; continue; } ans++; while(1){ MinMax(now + 1,now + ans * 2,&nwa,&nwb); if(nwa != -1){ ans = max(nwa - now,ans); now = nwb; break; } ans *= 2; ans++; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...