제출 #272923

#제출 시각아이디문제언어결과실행 시간메모리
272923cheissmartGap (APIO16_gap)C++14
100 / 100
75 ms1984 KiB
#include "gap.h" #include <bits/stdc++.h> #define F first #define S second #define PB push_back #define EB emplace_back #define MP make_pair #define V vector #define ALL(v) (v).begin(), (v).end() using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; long long findGap(int T, int N) { if(T == 1) { int l = 1, r = N; ll lb = 0, rb = 1e18; V<ll> v(N + 1); while(l <= r) { ll mn, mx; MinMax(lb, rb, &mn, &mx); v[l] = mn, v[r] = mx; l++, r--; lb = mn+1, rb = mx-1; } ll ans = 0; for(int i = 1; i < N; i++) ans = max(ans, v[i+1]-v[i]); return ans; } else { ll s, t, ans = 0; MinMax(0, 1e18, &s, &t); ll p = (t - s + N - 1) / N; ll pre = s; for(ll i = s+1; i <= t; i+=p+1) { ll mn, mx; MinMax(i, i+p, &mn, &mx); if(mn != -1) { ans = max(ans, mn - pre); pre = mx; } } return ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...