제출 #795139

#제출 시각아이디문제언어결과실행 시간메모리
795139ln_eCatfish Farm (IOI22_fish)C++17
0 / 100
953 ms724556 KiB
 #include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
#include "fish.h"
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
long long pref[5005][5005],a[5005][5005],sum[5005][5005],suf[5005][5005];
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y, std::vector<int> W) {
for(ll i=0;i<M;i++)
{
    a[X[i]+1][Y[i]+1]+=W[i];
}
for(ll i=1;i<=N;i++)
{
    for(ll j=1;j<=N;j++)
    {
        sum[i][j]=sum[i][j-1];
        sum[i][j]+=a[i][j];
    }
}
long long ans=0;
for(ll j=1;j<=N;j++)
{
    pref[0][j]=-LINF;
}
for(ll i=1;i<=N;i++)
{
    for(ll j=0;j<=N;j++)
    {
        for(ll k=0;k<=N;k++)
        {
            ll val=pref[i-1][k];
            if(k>j){
                val+=sum[i][k]-sum[i][j-1];
            }
            pref[i][j]=max(pref[i][j],val);
        }
    }
}
for(ll j=1;j<=N;j++)
{
    suf[N+1][j]=-LINF;
}
for(ll i=N;i>=1;i--)
{
for(ll j=0;j<=N;j++)
    {
        for(ll k=0;k<=N;k++)
        {
            ll val=suf[i+1][k];
            if(k>j){
                val+=sum[i][k]-sum[i][j-1];
            }
            suf[i][j]=max(suf[i][j],val);
        }
    }
}
for(ll i=1;i<=N;i++)
{
    for(ll j=0;j<=N;j++)
    {
        for(ll k=0;k<=N;k++)
        {
            ans=max(ans,pref[i-1][j]+suf[i+1][k]+sum[i][max(k,j)]);
            }
}
}
return ans;
}
#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...