이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include <atcoder/string>
// #include <atcoder/lazysegtree>
using namespace std;
using ll = long long;
using ull = unsigned long long;
// using mint = atcoder::modint998244353;
int INF = numeric_limits<int>::max() >> 1;
ll INFL = numeric_limits<ll>::max() >> 1;
ll mod = 998244353;
vector<ll> prefixSums;
ll getSum(int l, int r)
{
return prefixSums[r + 1] - prefixSums[l];
}
double computeLength(double start, vector<ll> &a, bool returnRealValue = false)
{
int n = a.size(), l = 0, r = n - 1;
double maxRight = (double)getSum(l, r) / n, maxLeft = maxRight;
for (int i = 0; i < n - 1; i++)
{
if ((double)getSum(l, r - 1) / (r - l) >= start)
{
maxLeft = min(maxLeft, (double)getSum(l, r - 1) / (r - l));
r--;
}
else
{
maxRight = max(maxRight, (double)getSum(l + 1, r) / (r - l));
l++;
}
}
if (returnRealValue)
{
return maxRight - maxLeft;
}
return maxRight - start;
}
void solve()
{
ll n;
cin >> n;
vector<ll> a(n);
prefixSums.resize(n + 1);
prefixSums[0] = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
prefixSums[i + 1] = prefixSums[i] + a[i];
}
double l = a[0], r = (double)prefixSums[n] / n, ll, rr;
for (int i = 0; i < 1000; i++)
{
ll = (2 * l + r) / 3;
rr = (l + 2 * r) / 3;
auto len1 = computeLength(ll, a), len2 = computeLength(rr, a);
if (len1 > len2)
{
l = ll;
}
else
{
r = rr;
}
}
cout << fixed << setprecision(12) << computeLength(l, a, true) << endl;
}
int main()
{
ios::sync_with_stdio(false);
// precompute(200005);
int t;
t = 1;
// cin >> t;
for (int i = 1; i <= t; i++)
{
// cout << "Case #" << i << ": ";
solve();
}
return 0;
};
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |