Submission #702762

#TimeUsernameProblemLanguageResultExecution timeMemory
702762acceptifyCatfish Farm (IOI22_fish)C++17
9 / 100
31 ms11212 KiB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mxn = 1e5 + 5;

ll n, m, w[mxn], dp[mxn][2][2][2], res = 0;

ll max_weights(int N, int M, vector<int> X, vector<int> Y, vector<int> W) {
    n = N, m = M;
    for (int i = 0; i < m; i++) w[X[i] + 1] = W[i];
    if (n < 3) return max(w[1], w[2]);
    dp[3][0][0][0] = 0;
    dp[3][0][0][1] = w[2];
    dp[3][0][1][0] = w[1];
    dp[3][0][1][1] = w[1];
    dp[3][1][0][0] = w[2];
    dp[3][1][0][1] = w[2];
    dp[3][1][1][0] = 0;
    dp[3][1][1][1] = 0;
    for (int i = 4; i <= n; i++) {
        for (int h = 0; h <= 1; h++) for (int h1 = 0; h1 <= 1; h1++) for (int h2 = 0; h2 <= 1; h2++) {
            for (int h3 = 0; h3 <= 1; h3++) {
                dp[i][h2][h1][h] = max(dp[i][h2][h1][h], dp[i - 1][h3][h2][h1] + ((h2 || h) && !h1 ? w[i - 1] : 0));
            }
        }
    }
    for (int h = 0; h <= 1; h++) for (int h1 = 0; h1 <= 1; h1++) for (int h2 = 0; h2 <= 1; h2++) {
        res = max(res, dp[n][h2][h1][h] + (h1 && !h ? w[n] : 0));
    }
    return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...