# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
876554 | 2023-11-21T23:56:34 Z | AlphaMale06 | Gap (APIO16_gap) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> //#include "gap.h" using namespace std; using ll=long long; long long findGap(int subt, int n){ if(subt==1){ ll mn=0; ll mx=1e18; ll a[n]; for(int i=0; i< (n+1)/2; i++){ MinMax(mn, mx, &mn, &mx); a[i]=mn; a[n-i-1]=mx; mn++; mx--; } ll ans=0; for(int i=1; i<n; i++){ ans=max(ans, a[i]-a[i-1]); } return ans; } else{ ll mn=0; ll mx=1e18; MinMax(mn, mx, &mn, &mx); ll mngap=(mx-mn+n-2)/(n-1)+1; ll l=mn+1; while(true){ ll qmn=l; if(mx-qmn+1<mngap)break; ll qmx=l+mngap-1; MinMax(qmn, qmx, &qmn, &qmx); if(qmx==-1){ while(true){ ll posgp=2*mngap; ll qmn2=l; ll qmx2=l+posgp-1; if(qmx2>=mx){ qmx2=mx-1; MinMax(qmn2, qmx2, &qmn2, &qmx2); if(qmx2==-1){ return mx-l+1; } else{ return qmx2-l+1; } } MinMax(qmn2, qmx2, &qmn2, &qmx2); if(qmx2==-1){ mngap=posgp+1; } else{ mngap=qmn2-l+2; l=qmx2+1; break; } } } else{ if(qmx==qmn && qmx==l+mngap-1){ mngap++; } l=qmx+1; } } return mngap-1; } }