제출 #672276

#제출 시각아이디문제언어결과실행 시간메모리
672276Dan4LifeGap (APIO16_gap)C++17
30 / 100
3098 ms5732 KiB
#include <bits/stdc++.h> #include "gap.h" using namespace std; //#define int long long using ll = long long; #define fi first #define se second #define pb push_back #define all(a) a.begin(),a.end() #define sz(a) (int)a.size() const int maxn = 5e5+10; const ll LINF = (ll)2e18; ll findGap(int T, int n) { ll s=0, t=LINF,mn,mx,ans=0; set<ll> S; S.clear(); if(T==1){ vector<ll> v; v.clear(); int x = (n+1)/2; while(x--) MinMax(s,t,&mn,&mx), v.pb(mn), v.pb(mx), s=mn+1, t=mx-1; sort(all(v)); for(int i = 0; i < sz(v)-1; i++) ans = max(ans, v[i+1]-v[i]); return ans; } while(sz(S)<n){ int r = t; while(s<r and sz(S)<n){ MinMax(s,r,&mn,&mx); if(mn!=-1) S.insert(mn),s=mn+1; if(mx!=-1) S.insert(mx),r=mx-1; if(mx==-1 or mx==mn) break; } } while(sz(S)>1){ auto itr = S.begin(); auto itr2 = itr; itr2++; ans = max(ans, *itr2-*itr); S.erase(S.begin()); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...