Submission #657849

# Submission time Handle Problem Language Result Execution time Memory
657849 2022-11-11T14:37:17 Z chenwz Seesaw (JOI22_seesaw) C++11
1 / 100
2000 ms 596 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
// const double oo = 1e18;  // +∞
#define _all(i, a, b) for (int i = (a); i <= (int)(b); ++i)
struct Seg {
  int l, r;
  bool operator<(const Seg& s) const {
    if (l != s.l) return l < s.l;
    return r < s.r;
  }
};
using VD = vector<double>;
VD S;
double ave(int l, int r) { return (S[r] - S[l - 1]) / (r - l + 1); }
bool inRange(double x, double l, double r) { return l <= x && x <= r; }
bool check(int n, double cl, double cr) {
  queue<Seg> Q;
  Seg s{1, n};
  vector<vector<bool>> Vis(n + 1, vector<bool>(n + 1));
  if (inRange(ave(s.l, s.r), cl, cr)) Q.push({s.l, s.r}), Vis[s.l][s.r] = true;
  while (!Q.empty()) {
    Seg s = Q.front();
    Q.pop();
    if (s.l == s.r) return true;
    vector<Seg> vs{{s.l + 1, s.r}, {s.l, s.r - 1}};
    for (Seg ns : vs)
      if (inRange(ave(ns.l, ns.r), cl, cr) && !Vis[ns.l][ns.r])
        Q.push(ns), Vis[ns.l][ns.r] = true;
  }
  return false;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n;
  cin >> n, S.resize(n + 1);
  for (int i = 1, a; i <= n; i++) cin >> a, S[i] = S[i - 1] + a;
  set<double> s0;  // 所有子区间的重心
  _all(i, 1, n) _all(j, i, n) s0.insert(ave(i, j));
  VD C(begin(s0), end(s0));  // 所有可能的左右边界一定都是某个重心
  int CL = C.size();
  double w = 1e18;
  _all(L, 0, CL - 1) _all(R, L, CL - 1) {
    // printf("%.2lf-%.2lf: %.2lf\n", C[L], C[R], C[R] - C[L]);
    if (check(n, C[L], C[R])) w = min(w, C[R] - C[L]);
  }
  printf("%.10lf\n", w);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 212 KB Output is correct
3 Correct 61 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 212 KB Output is correct
3 Correct 61 ms 316 KB Output is correct
4 Execution timed out 2076 ms 596 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 212 KB Output is correct
3 Correct 61 ms 316 KB Output is correct
4 Execution timed out 2076 ms 596 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 63 ms 212 KB Output is correct
3 Correct 61 ms 316 KB Output is correct
4 Execution timed out 2076 ms 596 KB Time limit exceeded
5 Halted 0 ms 0 KB -