이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define double long double
#define endl '\n'
#define sz(a) (int)a.size()
#define pb push_back
#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
ll const INF = LONG_LONG_MAX;
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y, std::vector<int> w)
{
    vector<vector<ll>> val(n+5, vector<ll>(n+5, 0)), pref(n+5, vector<ll>(n+5, 0));
    for(int i=0;i<m;i++)
    {
        val[x[i]+1][y[i]+1]=w[i];
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            pref[i][j]=pref[i][j-1]+val[i][j];
        }
    }
    vector<vector<vector<ll>>> dp(n+5, vector<vector<ll>>(n+5, vector<ll>(2, 0)));
    for(int j=1;j<=n;j++)
    {
        dp[1][j][0]=dp[1][j-1][0]+val[2][j];
        dp[1][j][1]=dp[1][j-1][1]+val[2][j];
    }
    for(int i=2;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            for(int k=1;k<=j;k++)
            {
                dp[i][j][0]=max(dp[i][j][0], dp[i-1][k][0]+pref[i-1][j]-pref[i-1][k]-pref[i][k]+pref[i+1][j]);
            }
            for(int k=n;k>=j;k--)
            {
                dp[i][j][1]=max(dp[i][j][1], dp[i-1][k][1]-pref[i][j]+pref[i+1][j]);
                dp[i][j][1]=max(dp[i][j][1], dp[i-1][k][0]-pref[i][j]+pref[i+1][j]);
            }
            for(int k=0;k<=n;k++)
            {
                ll val=0;
                if(k<=j)
                {
                    val=max(val, dp[i-2][k][0]+pref[i-1][j]-pref[i-1][k]+pref[i+1][j]);
                    val=max(val, dp[i-2][k][1]+pref[i-1][j]-pref[i-1][k]+pref[i+1][j]);
                }
                else
                {
                    val=max(val, dp[i-2][k][0]+pref[i+1][j]);
                    val=max(val, dp[i-2][k][1]+pref[i+1][j]);
                }
                dp[i][j][0]=max(dp[i][j][0], val);
                dp[i][j][1]=max(dp[i][j][1], val);
            }
        }
    }
//    cout<<endl<<endl;
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=n;j++)
//        {
//            cout<<dp[i][j][0]<<' ';
//        }
//        cout<<endl;
//    }
//    cout<<endl<<endl;
//    for(int i=0;i<=n;i++)
//    {
//        for(int j=0;j<=n;j++)
//        {
//            cout<<dp[i][j][1]<<' ';
//        }
//        cout<<endl;
//    }
//    cout<<endl<<endl;
    ll ans=0;
    for(int i=0;i<=n;i++)
        ans=max(ans, max(dp[n][i][0], dp[n][i][1]));
    return ans;
}
| # | 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... |