QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678500 | #8242. V-Diagram | aYi_7# | WA | 86ms | 3940kb | C++17 | 1.9kb | 2024-10-26 15:10:26 | 2024-10-26 15:10:28 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
void solve () {
int n;
std::cin >> n;
std::vector<int> a(n + 2), sum(n + 2);
for(int i = 1; i <= n; i++) {
std::cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
std::vector<int> pre(n + 2), nex(n + 2);
auto pre1 = pre, nex1 = nex;
for(int i = 1; i <= n; i++) {
if(i == 1) {
pre[i] = a[i];
pre1[i] = 1;
}else {
if(pre[i - 1] >= a[i] * pre1[i - 1]) {
pre[i] = pre[i - 1] + a[i];
pre1[i] = pre1[i - 1] + 1;
}else {
pre[i] = a[i];
pre1[i] = 1;
}
}
}
for(int i = n; i >= 1; i--) {
if(i == n) {
nex[i] = a[i];
nex1[i] = 1;
}else {
if(nex[i + 1] >= a[i] * nex1[i + 1]) {
nex[i] = nex[i + 1] + a[i];
nex1[i] = nex1[i + 1] + 1;
}else {
nex[i] = a[i];
nex1[i] = 1;
}
}
}
double ans = 0;
// for(int i = 2; i < n; i++) {
// if(a[i] < a[i - 1] && a[i] < a[i + 1]) {
// // std::cout << a[i] << ' ';
// ans = std::max(ans, ((double)a[i] + (double)pre[i - 1] + (double)nex[i + 1]) / (1. + (double)pre1[i - 1] + (double)nex1[i + 1]));
// }
// }
for(int i = 2; i < n; i++) {
if(pre1[i] + nex1[i] - 1 >= 3) {
ans = std::max(ans, ((double)pre[i] + (double)nex[i] - (double)a[i]) / ((double)pre1[i] + (double)nex1[i] - 1.));
}
}
// std::cout << ans << '\n';
printf("%.20f\n", ans);
}
/*
2
4
8 2 7 10
6
9 6 5 3 4 8
*/
signed main () {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
for(int i = 0; i < t; ++i) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3860kb
input:
2 4 8 2 7 10 6 9 6 5 3 4 8
output:
6.75000000000000000000 5.83333333333333303727
result:
ok 2 numbers
Test #2:
score: 0
Accepted
time: 86ms
memory: 3720kb
input:
100000 3 948511478 739365502 813471668 3 881046825 27458122 398507422 3 987554257 399092415 924260278 3 984128569 125199021 716360525 3 529589236 45783262 313507287 3 645443456 85994112 226010681 3 914820717 228360911 572267310 3 418958362 56703604 195276041 3 64461646 26764720 26995581 3 914535039 ...
output:
833782882.66666662693023681641 435670789.66666668653488159180 770302316.66666662693023681641 608562705.00000000000000000000 296293261.66666668653488159180 319149416.33333331346511840820 571816312.66666662693023681641 223646002.33333334326744079590 39407315.66666666418313980103 383253737.666666686534...
result:
ok 100000 numbers
Test #3:
score: -100
Wrong Answer
time: 23ms
memory: 3940kb
input:
10000 4 194123849 79274911 191162487 570110764 86 957917218 915359202 914726017 873273226 867724859 867674150 809652204 805531383 745262007 743835491 727071232 714782071 645394643 639432679 594879540 587173904 583418126 560538589 518721836 469558994 427721766 411582333 404948350 402948978 357228675 ...
output:
258668002.75000000000000000000 971673720.33333337306976318359 849387192.00000000000000000000 986908128.00000000000000000000 630796860.33333337306976318359 879892783.66666662693023681641 964329404.00000000000000000000 367779464.00000000000000000000 870415123.66666662693023681641 912377824.66666662693...
result:
wrong answer 2nd numbers differ - expected: '527118856.7555556', found: '971673720.3333334', error = '0.8433674'