QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215001#7339. A Really Odd SequenceSalmakaramAC ✓378ms144240kbC++141.1kb2023-10-15 02:05:112023-10-15 02:05:11

Judging History

This is the latest submission verdict.

  • [2023-10-15 02:05:11]
  • Judged
  • Verdict: AC
  • Time: 378ms
  • Memory: 144240kb
  • [2023-10-15 02:05:11]
  • 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;
    ret = LONG_LONG_MIN;
    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, solve(0, 0, i));
    }

    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;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 11792kb

input:

1
4
8 -7 9 1

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 378ms
memory: 144240kb

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