제출 #1225139

#제출 시각아이디문제언어결과실행 시간메모리
1225139trimkus메기 농장 (IOI22_fish)C++20
0 / 100
966 ms2162688 KiB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void chmax(ll& x, ll y) {
  x = max(x, y);
}

long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
    vector<vector<ll>> a(N + 3, vector<ll>(N + 3));
    for (int i = 0; i < M; ++i) {
        a[X[i] + 1][Y[i] + 1] += W[i];
    }
    vector<vector<vector<ll>>> dp(N + 2, vector<vector<ll>>(N + 2, vector<ll>(2)));
    // 1 - for hi < h(i - 1)
    // 0 - for hi >= h(i - 1)
    for (int i = 2; i <= N; ++i) {
      ll res = 0;
      for (int j = N; j >= 0; --j) {
        res = max(res, max(dp[i - 1][j][0], dp[i - 1][j][1]));
        dp[i][j][1] = max(dp[i][j][1], res);
        res += a[i][j];
      }
      res = 0;
      for (int j = 0; j <= N; ++j) {
        res = max(res, dp[i - 1][j][1]);
        dp[i][j][0] = max(res, dp[i][j][0]);
      }
      res = 0;
      for (int j = 0; j <= N; ++j) {
        res = max(res + a[i - 1][j], dp[i][j][0]);
        dp[i][j][0] = max(dp[i][j][0], res);
      }

    }
    // for (int i = 1; i <= N; ++i) {
    //   for (int j = 0; j <= N; ++j) {
    //     for (int k = 0; k < 2; ++k) {
    //       cerr << dp[i][j][k] << " ";
    //     }
    //     cerr << "\n";
    //   }
    //   cerr << "\n";
    // }
    // cerr << "\n";
    ll res = 0;
    for (int i = 0; i <= N; ++i) {
      for (int j = 0; j <= N; ++j) {
        for (int k = 0; k < 2; ++k) {
          chmax(res, dp[i][j][k]);
        }
      }
    }
    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...