Submission #657849

#TimeUsernameProblemLanguageResultExecution timeMemory
657849chenwzSeesaw (JOI22_seesaw)C++11
1 / 100
2076 ms596 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...