QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#93759 | #6191. Hard Problem | cowmoo | WA | 2ms | 3512kb | C++14 | 2.9kb | 2023-04-02 09:55:04 | 2023-04-02 09:55:07 |
Judging History
answer
#include <iostream>
using namespace std;
#define MAXN 100010
long long arr[MAXN];
long long solve()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
}
arr[n++] = 0;
arr[n++] = 0;
arr[n] = 0;
arr[n + 1] = 0;
long long prev[] = {0, 0};
for (int i = 0; i < n; i++)
{
arr[i] -= prev[i % 2];
prev[i % 2] += arr[i];
}
// for (int i = 0; i < n; i++)
// cout << arr[i] << " ";
// cout << endl;
long long doubles = 0, singles[2] = {0, 0};
long long ans = 0;
for (int i = 0; i < n; i++)
{
//cout << arr[i] << " ";
if (arr[i] > 0)
{
if (i + 1 < n && arr[i + 1] > 0)
{
if (arr[i] < arr[i + 1])
{
doubles += arr[i];
arr[i + 1] -= arr[i];
arr[i] = 0;
}
else
{
doubles += arr[i + 1];
singles[i % 2] += arr[i] - arr[i + 1];
arr[i + 1] = 0;
arr[i] = 0;
}
}
else
{
singles[i % 2] += arr[i];
arr[i] = 0;
}
}
else if (arr[i] < 0)
{
long long amt = min(doubles, -arr[i]);
//if <= 0 then 0
//if (i + 2 < n && arr[i + 2] > 0)
//{
amt = min(amt, max(0ll, (arr[i + 2] <= 0 ? 0 : arr[i + 2]) - arr[i + 1]));
//}
doubles -= amt;
ans += amt;
arr[i] += amt;
if (i + 1 < n)
{
arr[i + 1] += amt;
}
if (arr[i] < 0)
{
singles[i % 2] += arr[i];
ans -= arr[i];
arr[i] = 0;
if (singles[i % 2] < 0)
{
long long amt = -singles[i % 2];
doubles -= amt;
singles[0] += amt;
singles[1] += amt;
}
}
}
//cout << i << ": " << ans << " " << doubles << " " << singles[0] << " " << singles[1] << endl;
}
return ans + doubles + singles[0] + singles[1];
}
int main()
{
int t;
cin >> t;
while (t--)
{
cout << solve() << endl;
}
}
/*
3
5
2 1 2 1 2
8
1000000000 1000000000 0 1000000000 1000000000 0 1000000000 1000000000
13
1 1 4 5 1 4 1 9 1 9 8 1 0
8
1 1 0 1 1 0 1 1
5
100 3 3 10 11
97 0 0 7 8: 3
0 0 0 7 8: 100
1 9 8 7 3 90 2 3 2 0
0 8 7 6 2 89 1 2 1 0 : 1
0 8 6 6 1 89 0 2 0 0 : 1
0 6 6 4 1 87 0 0 0 0 : 2
0 5 5 3 0 86 0 0 0 0 : 1
0 0 0 0 0 0 0 0 0 0 : 91
10
1 9 8 7 3 90 2 3 2 0
9
1 9 8 7 3 90 2 3 2
*/
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 3416kb
input:
3 5 2 1 2 1 2 8 1000000000 1000000000 0 1000000000 1000000000 0 1000000000 1000000000 13 1 1 4 5 1 4 1 9 1 9 8 1 0
output:
2 3000000000 19
result:
ok 3 number(s): "2 3000000000 19"
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3512kb
input:
5 50 3 4 10 2 9 1 2 1 3 8 8 4 0 7 5 4 4 3 9 7 4 1 3 5 2 1 5 10 1 5 9 2 2 4 9 10 10 0 1 0 6 2 1 4 4 1 0 10 9 8 50 447 695 336 2 590 444 493 390 62 255 475 342 518 539 780 636 811 813 231 990 804 778 742 627 555 625 211 843 200 638 340 172 99 866 189 125 51 406 294 409 158 126 489 402 256 433 121 546 ...
output:
77 5333 569279 72524204 7111068521
result:
wrong answer 3rd numbers differ - expected: '567261', found: '569279'