QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214972 | #7339. A Really Odd Sequence | Salmakaram | WA | 375ms | 144064kb | C++14 | 1.1kb | 2023-10-15 01:52:04 | 2023-10-15 01:52:04 |
Judging History
answer
#include <bits/stdc++.h>
#define Pc_champs ios_base::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;
#define ll long long
#define int long long
int const N = 1e6 + 1;
int n, idx;
int dp[2][2][N], vis[2][2][N];
int a[N];
int solve(bool odd, bool end, int i) {
if (i == n) return (!odd ? -1e17 : 0);
int &ret = dp[odd][end][i];
if (vis[odd][end][i] == idx) return ret;
vis[odd][end][i] = idx;
if (!end) ret = a[i] + solve(odd ^ 1, end, i + 1);
ret = max(ret, solve(odd, true, i + 1));
return ret;
}
void dowork() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int mx = LONG_LONG_MIN;
for (int i = 0; i < n; i++) {
mx = max(mx, a[i] + solve(1, 0, i + 1));
}
cout << mx;
}
signed main() {
Pc_champs;
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t = 1;
cin >> t;
idx = 1;
while (t--) {
dowork();
idx++;
cout << "\n";
//break;
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7732kb
input:
1 4 8 -7 9 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: -100
Wrong Answer
time: 375ms
memory: 144064kb
input:
59056 10 0 1 1 0 1 0 1 1 1 0 10 -1 -1 -1 1 0 0 1 0 0 1 10 1 0 0 1 1 1 -1 -1 0 1 10 -1 1 -1 1 0 1 1 0 -1 1 10 1 0 0 1 -1 0 -1 -1 -1 1 10 1 1 1 0 0 -1 -1 1 0 0 10 -1 1 0 0 1 -1 -1 0 -1 -1 10 1 -1 0 0 0 -1 -1 -1 -1 -1 10 0 0 0 1 1 0 0 1 -1 1 10 0 -1 0 0 1 0 1 1 1 0 10 0 0 0 0 1 -1 1 -1 -1 -1 10 -1 0 1 ...
output:
6 3 4 3 2 3 2 1 3 4 1 2 3 6 1 1 4 2 1 1 4 2 3 2 3 2 5 1 1 2 3 1 1 3 2 4 0 5 1 1 2 1 1 2 3 2 1 2 1 3 1 2 3 2 3 2 3 2 5 1 3 2 2 2 2 1 1 2 2 3 2 1 3 1 2 1 1 2 2 1 2 2 1 3 1 3 1 1 2 1 2 2 3 2 1 2 1 1 3 3 1 2 2 1 1 3 1 2 2 2 1 1 3 3 2 1 3 2 3 2 2 4 2 1 2 4 3 5 2 2 4 1 1 2 1 1 2 2 5 3 3 0 2 2 2 1 1 2 1 2 ...
result:
wrong answer 3rd numbers differ - expected: '3', found: '4'