QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#678481 | #8242. V-Diagram | aYi_7# | WA | 85ms | 3948kb | C++17 | 1.8kb | 2024-10-26 15:06:28 | 2024-10-26 15:06:32 |
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 - 1] + nex1[i] > 3) {
ans = std::max(ans, ((double)pre[i - 1] + (double)nex[i]) / ((double)pre1[i - 1] + (double)nex1[i]));
}
}
// std::cout << ans << '\n';
printf("%.20f\n", ans);
}
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: 3948kb
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: 85ms
memory: 3904kb
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: 27ms
memory: 3936kb
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 965303505.00000000000000000000 776664647.00000000000000000000 952248447.75000000000000000000 584267940.50000000000000000000 845012281.50000000000000000000 951419385.50000000000000000000 254833443.19999998807907104492 846915684.00000000000000000000 896190768.75000000000...
result:
wrong answer 2nd numbers differ - expected: '527118856.7555556', found: '965303505.0000000', error = '0.8312824'