QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#235468 | #3032. Cheese Game | piratZnachor# | AC ✓ | 101ms | 4856kb | C++14 | 1.0kb | 2023-11-02 19:52:32 | 2023-11-02 19:52:32 |
Judging History
answer
#include <bits/stdc++.h>
#include <cassert>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define vll vector<long long>
#define fi first
#define se second
void test_case() {
int n;
cin >> n;
vi a(n);
for (int i = 0; i < n; i ++) cin >> a[i];
if (n == 1) {
cout << a[0] << '\n';
return;
}
if (n == 2) {
cout << max(a[0], a[1]) << '\n';
return;
}
vi dp(n + 1, 0);
dp[1] = a[0];
dp[2] = a[1];
for (int i = 3; i <= n; i ++) {
dp[i] = max(dp[i-2] + a[i-1], dp[i-3] + a[i-1] + min(a[i-2], a[i-3]));
}
int ans = *max_element(all(dp));
cout << ans << '\n';
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc = 1;
cin >> tc;
while(tc--) {
test_case();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
input:
20 2 2 1 1 1000000 4 3 2 4 3 8 1000000 1000000 1000000 1000000 1000000 1000000 1000000 1000000 8 1000000 1000000 1000000 1 1000000 1000000 1000000 1000000 9 723059 133070 898168 961394 18457 175012 478043 176230 377374 8 289384 930887 692778 636916 747794 238336 885387 760493 8 516650 641422 202363 ...
output:
2 1000000 8 5000000 5000000 2691397 3314426 2475496 4999998 10 3 1 2 8 4000001 15 3213803 24 3000002 4
result:
ok 20 lines
Test #2:
score: 0
Accepted
time: 101ms
memory: 4856kb
input:
20 100000 859485 390674 819590 695284 505824 962572 577989 53378 307332 754253 103728 302519 19948 48169 659522 389802 262161 848413 224854 965949 70782 789156 772974 876205 410327 900390 392837 362222 582187 762071 74734 958024 152744 410676 169659 174919 373247 264000 744649 196931 18252 848376 15...
output:
33024883937 33135467117 66667000000 33237375393 58332975002 33104918259 33172888838 33156623430 33090460100 33042109608 32999667097 33111199056 3333366667 32982135568 33144273501 56831006063 33108905993 33124668910 33126313979 33069028435
result:
ok 20 lines