/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 5ms 5.066 MiB
#2 Wrong Answer 6ms 5.066 MiB
#3 Wrong Answer 6ms 5.062 MiB
#4 Wrong Answer 5ms 5.066 MiB
#5 Wrong Answer 49ms 5.023 MiB
#6 Wrong Answer 39ms 12.402 MiB
#7 Wrong Answer 39ms 12.312 MiB
#8 Wrong Answer 39ms 12.195 MiB
#9 Accepted 36ms 12.223 MiB
#10 Accepted 37ms 12.18 MiB
#11 Accepted 37ms 12.254 MiB
#12 Accepted 36ms 12.176 MiB
#13 Accepted 36ms 12.234 MiB
#14 Accepted 37ms 12.195 MiB
#15 Accepted 37ms 12.398 MiB
#16 Accepted 37ms 12.242 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];

ll rec(int idx, int lastTaken) {
    if (idx == n) {
        return 0;
    }
    ll &ret = dp[idx][lastTaken];
    if (~ret) {
        return ret;
    }
    ret = 0;
    if (lastTaken == 0) {
        ret = max(ret, b[idx] + rec(idx + 1, 1));
        ret = max(ret, c[idx] + rec(idx + 1, 2));
    }
    if (lastTaken == 1) {
        ret = max(ret, a[idx] + rec(idx + 1, 0));
        ret = max(ret, c[idx] + rec(idx + 1, 2));
    }
    if (lastTaken == 2) {
        ret = max(ret, a[idx] + rec(idx + 1, 0));
        ret = max(ret, b[idx] + rec(idx + 1, 1));
    }
    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(dp, -1, sizeof dp);
        ll res = max({rec(0, 0), rec(0, 1), rec(0, 2)});
        cout << res << 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 17:24:45
Judged At
2024-10-03 13:55:54
Judged By
Score
66
Total Time
49ms
Peak Memory
12.402 MiB