제출 #321108

#제출 시각아이디문제언어결과실행 시간메모리
321108MetBGap (APIO16_gap)C++14
100 / 100
73 ms2084 KiB
#include "gap.h" #include <bits/stdc++.h> typedef long long ll; typedef long double ld; using namespace std; ll findSmall(int N) { vector <ll> v (N); ll mn, mx; MinMax (1, 1e18, &mn, &mx); ll s = mn, e = mx; v[0] = s, v[N-1] = e; int l = 0, r = N - 1; while (l + 1 < r) { MinMax(v[l] + 1, v[r] - 1, &s, &e); v[++l] = s, v[--r] = e; } for (int i = 1; i < N; i++) { v[i-1] = v[i] - v[i-1]; } return *max_element(v.begin(), v.end() - 1); } ll findGap(int T, int N) { if (T == 1) { return findSmall(N); } ll mn, mx; MinMax (1, 1e18, &mn, &mx); ll s = mn, e = mx; ld d = (ld) (mx - mn - 2) / N; ld l = mn + 1, r = mn + 1 + d; ll gap = 0, mx_old = mn, last_ir = s; for (int i = 0; i < N - 1; i++) { ll il = ceil (l - 1e-7) + (ceil (l - 1e-7) == last_ir), ir = floor (r + 1e-7); //cout << il << ' ' << ir << endl; if (il > ir) continue; last_ir = ir; MinMax(il, ir, &mn, &mx); //cout << ' ' << mn << ' ' << mx << endl; if (mn != -1) { gap = max (gap, mn - mx_old); mx_old = mx; } l += d, r += d; } ll il = ceil (l - 1e-7) + (ceil (l + 1e-7) == mx_old), ir = floor (r + 1e-7); //cout << il << ' ' << ir << endl; if (il <= ir) MinMax(il, ir, &mn, &mx); //cout << ' ' << mn << ' ' << mx << endl; if (mn != -1 && il <= ir) { gap = max (gap, mn - mx_old); mx_old = mx; } gap = max (gap, e - mx_old); return gap; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...