답안 #1057232

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057232 2024-08-13T15:40:26 Z juicy Seesaw (JOI22_seesaw) C++17
100 / 100
33 ms 8884 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

int n;
int a[N];
long long pf[N];

double qry(int l, int r) {
  return (double) (pf[r] - pf[l - 1]) / (r - l + 1);
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pf[i] = pf[i - 1] + a[i];
  }
  double A = qry(1, n);
  vector<array<double, 2>> cands = {{A, A}};
  for (int l = 1; l < n; ++l) {
    int L = 1, R = n - l + 1, p = 0;
    while (L <= R) {
      int md = (L + R) / 2; 
      if (qry(md, md + l - 1) < A) {
        p = md;
        L = md + 1;
      } else {
        R = md - 1;
      }
    }
    cands.push_back({qry(p, p + l - 1), qry(p + 1, p + l)});
  }
  sort(cands.begin(), cands.end());
  double res = 1e9, mx = cands.back()[0];
  for (auto [x, y] : cands) {
    res = min(res, mx - x);
    mx = max(mx, y);
  }
  cout << fixed << setprecision(12) << res;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 32 ms 6864 KB Output is correct
13 Correct 31 ms 8884 KB Output is correct
14 Correct 32 ms 8660 KB Output is correct
15 Correct 33 ms 7968 KB Output is correct
16 Correct 32 ms 7380 KB Output is correct