/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 928.0 KiB
#2 Wrong Answer 2ms 1.062 MiB
#3 Wrong Answer 2ms 1.023 MiB
#4 Accepted 2ms 1.223 MiB
#5 Wrong Answer 27ms 1.25 MiB
#6 Accepted 40ms 12.191 MiB
#7 Accepted 40ms 12.164 MiB
#8 Accepted 39ms 12.164 MiB
#9 Accepted 35ms 12.062 MiB
#10 Accepted 35ms 12.012 MiB
#11 Accepted 36ms 12.211 MiB
#12 Accepted 37ms 12.215 MiB
#13 Accepted 37ms 12.227 MiB
#14 Accepted 37ms 12.109 MiB
#15 Accepted 37ms 12.219 MiB
#16 Accepted 37ms 12.062 MiB

Code

#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'

using namespace std;

const int N = 2e5 + 5;
int tc, n, m, a[N], b[N], c[N];
ll dp[N][3];
bool vis[N][3];

ll rec(int idx, int pre) {
    if (idx == n) {
        return 0;
    }
    ll &ret = dp[idx][pre];
    if (vis[idx][pre]) {
        return ret;
    }
    vis[idx][pre] = true;
    ret = INT_MIN;
    if (pre != 0) {
        ret = max(ret, a[idx] + rec(idx + 1, 0));
    }
    if (pre != 1) {
        ret = max(ret, b[idx] + rec(idx + 1, 1));
    }
    if (pre != 2) {
        ret = max(ret, c[idx] + rec(idx + 1, 2));
    }
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); // cout.tie(0);
    cin >> tc;
    while (tc--) {
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> b[i];
        }
        for (int i = 0; i < n; i++) {
            cin >> c[i];
        }
        memset(vis, false, sizeof vis);
        cout << rec(0, -1) << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Contest
TLE_Headquarters - round #1
Language
C++17 (G++ 13.2.0)
Submit At
2024-03-27 18:03:34
Judged At
2024-10-03 13:55:26
Judged By
Score
86
Total Time
40ms
Peak Memory
12.227 MiB