제출 #713182

#제출 시각아이디문제언어결과실행 시간메모리
713182lamGap (APIO16_gap)C++14
39.61 / 100
293 ms6704 KiB
#include <bits/stdc++.h> #define ll long long #include "gap.h" using namespace std; #define ll long long const int maxn = 1e5 + 10; int n; ll a[maxn]; ll sub1() { int l=1; int r=n; ll s = 0; ll t = 1e18; while (l<=r) { ll *mx, *mn; ll mmax, mmin; mx = &mmax; mn = &mmin; // cerr<<l<<' '<<r<<' '<<s<<' '<<t<<endl; MinMax(s,t,mn,mx); s = (mmin)+1; t = (mmax)-1; a[l++]=mmin; a[r--]=mmax; } ll ans = 0; for (int i=2; i<=n; i++) { if (ans<a[i]-a[i-1]) ans=a[i]-a[i-1]; } return ans; } set<ll> b; const ll sq = 100; void dnc(ll s, ll t) { if (s>t) return; ll *mn,*mx; ll mmin,mmax; mx = &mmax; mn=&mmin; MinMax(s,t,mn,mx); if (mmin == -1) return; s = mmin+1; t = mmax-1; b.insert(mmin); b.insert(mmax); if (mmin==mmax) return; ll dist = 1LL*(t-s)/sq; ll last = s; for (ll i=1; i<sq; i++) { ll next = min(last + dist,t); dnc(last,next); last = next + 1; if (last > t) break; } if (last <= t) dnc(last,t); } ll sub2() { dnc(0,1e18); int m=0; for (ll i:b) a[++m] = i; ll ans = 0; assert(n==m); for (int i=2; i<=n; i++) ans=max(ans,a[i]-a[i-1]); return ans; } ll findGap(int T, int N) { n=N; if (T==1) return sub1(); else return sub2(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...