이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#ifdef NYAOWO
#include "grader.cpp"
#endif
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second 
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;
inline void chmax(int &x, int val) { x = max(x, val); }
const int MAXN = 300;
const int INF = 1e15;
int n, m;
int pre[MAXN + 10][MAXN + 10];
int dp1[MAXN + 10][MAXN + 10];
int dp2[MAXN + 10][MAXN + 10];
int sum(int x, int u, int d) {
    if(u < d) return 0;
    int res = pre[x][u];
    if(d) res -= pre[x][d - 1];
    return res;
}
long long max_weights(i32 N, i32 M, vector<i32> X, vector<i32> Y,
                      vector<i32> W) {
    n = N;
    m = M;
    memset(pre, 0, sizeof(pre));
    For(i, 0, m - 1) {
        pre[X[i] + 1][Y[i] + 1] += W[i];
    }
    For(i, 1, n) For(j, 1, n) {
        pre[i][j] += pre[i][j - 1];
    }
    For(i, 0, n + 1) For(j, 0, n + 1) {
        dp1[i][j] = dp2[i][j] = -INF;
    }
    dp2[0][0] = 0;
    For(i, 1, n + 1) {
        For(j, 1, n) {
            dp1[i][j] = dp2[i - 1][0] + sum(i - 1, j, 0);
            For(j2, 1, j) chmax(dp1[i][j], dp1[i - 1][j2] + sum(i - 1, j, j2 + 1));
        }
        For(j, 0, n) {
            dp2[i][j] = dp1[i - 1][j] + sum(i, j, 0);
            For(j2, j, n) chmax(dp2[i][j], dp2[i - 1][j2] + sum(i, j, 0) - sum(i - 1, j, 0));
        }
    }
    // Forr(j, n, 0) For(i, 1, n + 1) {
    //     cerr << dp1[i][j] << " \n"[i == n + 1];
    // }
    // cerr << "\n";
    // Forr(j, n, 0) For(i, 1, n + 1) {
    //     cerr << dp2[i][j] << " \n"[i == n + 1];
    // }
    int ans = 0;
    For(j, 0, n) chmax(ans, dp2[n + 1][j]);
    return ans;
}
/*
5 4
0 2 5
1 1 2
4 4 1
3 3 3
8
*/
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |