QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#455945 | #4355. Seesaw | nhuang685# | 0 | 0ms | 4052kb | C++20 | 1.4kb | 2024-06-27 03:55:22 | 2024-06-27 03:55:22 |
answer
#include <bits/stdc++.h>
using db = long double;
auto main() -> int {
std::cin.tie(nullptr)->sync_with_stdio(false);
int n;
std::cin >> n;
std::vector<int> a(n);
int64_t sum = 0;
for (auto &i : a) {
std::cin >> i;
sum += i;
}
db avg = 1.0l * sum / n;
int li = 0, ri = 0;
for (int i = 0; i < n - 1; ++i) {
if (a[i] <= avg && avg <= a[i + 1]) {
if (avg - a[i] <= a[i + 1] - avg) {
li = ri = i;
} else {
li = ri = i + 1;
}
}
}
db l = a[li], r = a[li];
db csum = a[li];
for (int i = 0; i < n - 1; ++i) {
if (li == 0) {
csum += a[ri + 1];
++ri;
l = std::min(l, csum / (i + 2));
r = std::max(r, csum / (i + 2));
} else if (ri == n - 1) {
csum += a[li - 1];
--li;
l = std::min(l, csum / (i + 2));
r = std::max(r, csum / (i + 2));
} else {
db avg1 = (csum + a[li - 1]) / (i + 2);
db avg2 = (csum + a[ri + 1]) / (i + 2);
if (l <= avg1 && avg1 <= r) {
csum += a[li - 1];
--li;
} else if (l <= avg2 && avg2 <= r) {
csum += a[ri + 1];
++ri;
} else if (l - avg1 <= avg2 - r) {
csum += a[li - 1];
--li;
l = avg1;
} else {
csum += a[ri + 1];
++ri;
r = avg2;
}
}
}
std::cout << std::fixed << std::setprecision(10) << r - l << '\n';
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 0ms
memory: 4052kb
input:
2 925278587 966813970
output:
20767691.5000000000
result:
ok found '20767691.500000000', expected '20767691.500000000', error '0.000000000'
Test #2:
score: -1
Wrong Answer
time: 0ms
memory: 3812kb
input:
20 7902238 121690240 160345001 255257832 269315023 288280211 296247186 353929891 494812700 530994847 567379029 567478415 612943598 644028258 654380821 696407711 708542915 738196686 743020754 760907139
output:
57459167.2500000000
result:
wrong answer 1st numbers differ - expected: '52991294.1666667', found: '57459167.2500000', error = '0.0843133'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%