답안 #672959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
672959 2022-12-19T08:03:51 Z MilosMilutinovic Seesaw (JOI22_seesaw) C++14
100 / 100
97 ms 17924 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<double> b(n);
  b[0] = a[0];
  for (int i = 1; i < n; i++) {
    b[i] = b[i - 1] + a[i];
  }
  auto Get = [&](int l, int r) {
    double s = b[r];
    if (l > 0) {
      s -= b[l - 1];
    }
    return s / (r - l + 1);
  };
  double c = Get(0, n - 1);
  vector<double> L(n);
  vector<double> R(n);
  for (int i = 1; i < n; i++) {
    {
      int l = 0, r = n - i, pos = -1;
      while (l <= r) {
        int mid = l + r >> 1;
        if (Get(mid, mid + i - 1) <= c) {
          pos = mid;
          l = mid + 1;
        } else {
          r = mid - 1;
        }
      }
      if (pos == -1) {
        L[i] = -1;
      } else {
        L[i] = Get(pos, pos + i - 1);
      }
    }
    {
      int l = 0, r = n - i, pos = -1;
      while (l <= r) {
        int mid = l + r >> 1;
        if (Get(mid, mid + i - 1) >= c) {
          pos = mid;
          r = mid - 1;
        } else {
          l = mid + 1;
        }
      }
      if (pos == -1) {
        R[i] = 2e9;
      } else {
        R[i] = Get(pos, pos + i - 1);
      }
    }
  }
//  for (int i = 1; i < n; i++) {
//    cout << fixed << setprecision(10) << L[i] << " " << R[i] << '\n';
//  }
  vector<int> order(n);
  iota(order.begin(), order.end(), 0);
  order.erase(order.begin());
  sort(order.begin(), order.end(), [&](int i, int j) {
    return L[i] < L[j];
  });
  multiset<double> st;
  st.insert(c);
  double ans = c - *min_element(L.begin() + 1, L.end());
  for (int i : order) {
    ans = min(ans, *prev(st.end()) - L[i]);
    st.insert(R[i]);
  }
  ans = min(ans, *prev(st.end()) - c);
  cout << fixed << setprecision(10) << ans << '\n';
  return 0;
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:33:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   33 |         int mid = l + r >> 1;
      |                   ~~^~~
seesaw.cpp:50:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   50 |         int mid = l + r >> 1;
      |                   ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 90 ms 17912 KB Output is correct
13 Correct 97 ms 17924 KB Output is correct
14 Correct 92 ms 17856 KB Output is correct
15 Correct 89 ms 17924 KB Output is correct
16 Correct 88 ms 17860 KB Output is correct