제출 #1135577

#제출 시각아이디문제언어결과실행 시간메모리
1135577Pekiban메기 농장 (IOI22_fish)C++20
3 / 100
101 ms28000 KiB
#include "fish.h"
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
using ll = long long;
ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W) {
    vector<array<ll, 2>> a[n];
    vector<ll> S[n];
    ll SUM = 0;
    for (int i = 0; i < m; ++i) a[X[i]].pb({Y[i], W[i]});
    for (int i = 0; i < n; ++i) {
        a[i].pb({-1, 0});
        sort(a[i].begin(), a[i].end());
        S[i] = {0};
        for (auto &[y, w] : a[i]) {
            if (y >= 0) {
                S[i].pb(S[i].back() + w);
            }
        }
        SUM += S[i].back();
    }
    if (n >= 300) {
        return SUM;
    }
    ll dp[n][n][2];
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) dp[i][j][0] = dp[i][j][1] = 0;
    }
    for (int i = 0; i < n; ++i) dp[0][i][0] = dp[0][i][1] = 0;
    auto sum = [&](int i, int h) {
        array<ll, 2> cr = {h, (int)1e9};
        return S[i][upper_bound(a[i].begin(), a[i].end(), cr) - a[i].begin() - 1];
    };
    ll mx = 0;
    for (int i = 1; i < n; ++i) {
        for (int h = 0; h < n; ++h) {
            if (i == 1) dp[i][h][0] = sum(0, h);
            for (int h2 = 0; h2 < n; ++h2) {
                if (h2 <= h) {
                    dp[i][h][0] = max(sum(i-1, h) - sum(i-1, h2) + dp[i-1][h2][0], dp[i][h][0]);
                }
                if (h2 >= h)    dp[i][h][1] = max(sum(i, h2) - sum(i, h) + dp[i-1][h2][1], dp[i][h][1]);
                if (i >= 2) dp[i][h][0] = max(sum(i-1, max(h, h2)) + dp[i-2][h2][1] , dp[i][h][0]);
            }
            mx = max({mx, dp[i][h][0], dp[i][h][1]});
        }
        dp[i][n][0] = dp[i][n][1] = max({dp[i][n][0], dp[i][n][1]});
    }
    return mx;
}
#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...