QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#214972#7339. A Really Odd SequenceSalmakaramWA 375ms144064kbC++141.1kb2023-10-15 01:52:042023-10-15 01:52:04

Judging History

This is the latest submission verdict.

  • [2023-10-15 01:52:04]
  • Judged
  • Verdict: WA
  • Time: 375ms
  • Memory: 144064kb
  • [2023-10-15 01:52:04]
  • Submitted

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'