QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201177 | #7339. A Really Odd Sequence | LilyWhite | AC ✓ | 104ms | 27124kb | C++20 | 2.1kb | 2023-10-05 12:56:15 | 2023-10-05 12:56:15 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repr(i, m, n) for (int i = (int)m; i <= (int)n; i++)
#define repd(i, m, n) for (int i = (int)m; i >= (int)n; i--)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#ifdef LILYWHITE
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) ;
#endif
const int __attribute__((unused)) INF = 0x3f3f3f3f;
template <typename T> inline T rd(T &x) {
x = 0;
T neg = 1;
char c = 0;
while (c < '0' || c > '9') {
if (c == '-')
neg = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - 48;
c = getchar();
}
x *= neg;
return x;
}
template <typename T, typename... Args> inline void rd(T &x, Args &...args) {
rd(x);
rd(args...);
}
#define MULTI
const int N = 1000100;
ll a[N], dp[N][2];
void Main() {
int n;
rd(n);
repn(i, n) {
dp[i][0] = dp[i][1] = 0;
}
repn(i, n) {
rd(a[i]);
}
for (int i = 1; i <= n; i++) {
dp[i][0] = max(dp[i - 1][1] + a[i], a[i]);
if (i > 1) dp[i][1] = dp[i - 1][0] + a[i];
}
// repn(i, n) cerr << dp[i][0] << ' ' << dp[i][1] << endl;
ll ans = -1e16;
repn(i, n) chmax(ans, dp[i][0]);
cout << ans << endl;
}
int main() {
#ifdef MULTI
int T;
rd(T);
while (T--)
#endif
Main();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5576kb
input:
1 4 8 -7 9 1
output:
10
result:
ok 1 number(s): "10"
Test #2:
score: 0
Accepted
time: 104ms
memory: 27124kb
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 3 3 1 3 1 1 3 4 1 2 3 6 1 1 4 2 1 1 4 1 3 2 3 1 5 1 1 2 3 1 1 2 2 3 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 1 1 3 1 3 1 1 2 1 2 2 3 2 1 2 1 1 3 3 1 1 2 1 1 3 1 2 2 1 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:
ok 59056 numbers