/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 1ms 532.0 KiB
#3 Wrong Answer 1ms 384.0 KiB

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 = -10000000000;
    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];
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                vis[i][j] = dp[i][j] = 0;
            }
        }
        ll Ans = rec(0, -1);
        cout << Ans << endl;
    }

    return 0;
}

Information

Submit By
Type
Submission
Problem
P1046 Maximum sum in 3-array
Contest
TLE_Headquarters - round #1
Language
C++20 (G++ 13.2.0)
Submit At
2024-03-27 18:17:42
Judged At
2024-11-11 03:37:12
Judged By
Score
1
Total Time
1ms
Peak Memory
532.0 KiB