QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#864574 | #4355. Seesaw | patgra | 0 | 0ms | 8024kb | C++20 | 3.8kb | 2025-01-20 19:20:27 | 2025-01-20 19:20:33 |
answer
#include <bits/stdc++.h>
#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))
constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl
#define ll long long
#define pb push_back
#define ld long double
using namespace std;
constexpr int maxn = 2e5 + 7;
constexpr ld eps = 1e-5;
int n;
ll arr[maxn];
ld bc, deviance[maxn][2];
bool canGo[maxn][2][2];
pair<int, int> intervals[maxn][2];
void calcGraph() {
rep(i, 0, n) bc += arr[i];
bc /= n;
DC << "Barycentre " << bc << eol;
rep(i, 0, n - 1) {
ld l = (bc - (i ? deviance[i - 1][0] : 0)) * (n - i);
ld m = (bc - (i ? deviance[i - 1][0] : 0)) * (n - i);
ld r = (bc + (i ? deviance[i - 1][1] : 0)) * (n - i);
l -= (i ? arr[intervals[i - 1][0].second] : arr[n - 1]);
m -= (i ? arr[intervals[i - 1][0].first] : arr[0]);
r -= (i ? arr[intervals[i - 1][1].first] : arr[0]);
l /= (n - i - 1), l -= bc;
m /= (n - i - 1), m -= bc;
r /= (n - i - 1), r -= bc;
DC << " At level " << i << " " << l << ' ' << m << ' ' << r << eol;
if(abs(m) <= eps) {
intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][0] : make_pair(0, n - 1));
intervals[i][0].first++, intervals[i][1].first++;
rep(ii, 0, 2) rep(iii, 0, 2) canGo[i][ii][iii] = true;
}
else if(m > 0) {
canGo[i][0][0] = canGo[i][0][1] = canGo[i][1][1] = true;
intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][0] : make_pair(0, n - 1));
intervals[i][0].second--;
intervals[i][1].first++;
deviance[i][0] = -l;
deviance[i][1] = m;
}
else {
canGo[i][0][0] = canGo[i][1][0] = canGo[i][1][1] = true;
intervals[i][0] = intervals[i][1] = (i ? intervals[i - 1][1] : make_pair(0, n - 1));
intervals[i][0].second--;
intervals[i][1].first++;
deviance[i][0] = -m;
deviance[i][1] = r;
}
DEBUG {
DC << " CanGo ";
rep(ii, 0, 2) rep(iii, 0, 2) DC << canGo[i][ii][iii] << ' '; DC << eol;
DC << " Intervals: (" << intervals[i][0].first << ' ' << intervals[i][0].second << ") (" << intervals[i][1].first << ' ' << intervals[i][1].second << ")" << eol;
DC << " Deviance: " << deviance[i][0] << ' ' << deviance[i][1] << eol;
}
}
}
void input() {
scanf("%d", &n);
rep(i, 0, n) scanf("%lld", arr + i);
}
bool remIsLeft[maxn];
ld maxLeft;
void maxDevLeft(ld maxRight, int start, bool skip) {
DC << "Going down with max = " << maxRight << " starting from " << start << ": ";
bool isLeft = (skip ? remIsLeft[start - 1] : false);
rep(i, start, n - 1) {
DC << isLeft << "(" << maxLeft << ") ";
if(canGo[i][(int)!isLeft][1] && deviance[i][1] - maxRight <= eps) isLeft = false;
else isLeft = true;
if(isLeft) maxLeft = max(maxLeft, deviance[i][(int)!isLeft]);
if(isLeft == remIsLeft[i] && skip) { DC << " skip " << eol; break; }
remIsLeft[i] = isLeft;
}
DC << isLeft << "(" << maxLeft << ") " << eol;
}
int main() {
input();
calcGraph();
priority_queue<pair<ld, int>> Q;
rep(i, 0, n - 1) Q.emplace(deviance[i][1], i + 1);
maxDevLeft(Q.top().first, 0, 0);
ld ans = maxLeft + Q.top().first;
Q.pop();
while(!Q.empty()) {
maxDevLeft(Q.top().first, Q.top().second, 1);
ld tmp = Q.top().first;
Q.pop();
if((!Q.empty() && tmp > eps) || (Q.empty() && abs(Q.top().first - tmp) > eps)) ans = min(ans, Q.top().first + maxLeft);
}
maxDevLeft(0, 0, 0);
ans = min(ans, maxLeft);
printf("%Lf", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 0ms
memory: 8024kb
input:
2 925278587 966813970
output:
20767691.500000
result:
ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 7924kb
input:
20 7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139
output:
16305733.000000
result:
wrong answer 1st numbers differ - expected: '52991294.1666667', found: '16305733.0000000', error = '0.6922941'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%