답안 #687632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687632 2023-01-26T17:11:14 Z Urvuk3 메기 농장 (IOI22_fish) C++17
0 / 100
23 ms 5676 KB
#include "fish.h"

#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(niz) { cerr<<#niz<<"="; for(auto _i:niz) cerr<<_i<<" "; cerr<<endl; }

long long max_weights(int N,int M,vector<int> X,vector<int> Y,vector<int> W){
    assert(N<=3000);
    vector<vector<int>> we(N,vector<int>(N,0));
    for(int i=0;i<M;i++){
        we[X[i]][Y[i]]=W[i];
    }
    vector<vector<vector<ll>>> dp(N,vector<vector<ll>>(N+1,vector<ll>(2,0)));
    for(int i=1;i<N;i++){
        vector<ll> pref(N,0); pref[0]=we[i-1][0];
        for(int j=1;j<N;j++){
            pref[j]=pref[j-1]+we[i-1][j];
        }

        //resavam kad opada
        ll pref_max=0;
        for(int tsz=N-1;tsz>=0;tsz--){
            pref_max=max(pref_max+we[i][tsz],dp[i-1][tsz][0]+we[i][tsz]);
            dp[i][tsz][0]=pref_max;
        }

        //resavam kada raste
        if(i>1){
            pref_max=0;
            for(int tsz=1;tsz<=N;tsz++){
                pref_max=max(pref_max,dp[i-2][tsz][0]);
                pref_max=max(pref_max,dp[i-2][tsz][1]);
                dp[i][tsz][1]=pref_max+pref[tsz-1];
            }
            pref_max=0;
            for(int tsz=N;tsz>=1;tsz--){
                pref_max=max(pref_max,dp[i-2][tsz][0]+pref[tsz-1]);
                pref_max=max(pref_max,dp[i-2][tsz][1]+pref[tsz-1]);
                dp[i][tsz][1]=max(dp[i][tsz][1],pref_max);
            }
        }
        pref_max=0;
        for(int tsz=2;tsz<=N;tsz++){
            pref_max=max(pref_max+we[i-1][tsz-1],dp[i-1][tsz][1]+we[i-1][tsz-1]);
            dp[i][tsz][1]=max(dp[i][tsz][1],pref_max);
        }
    }
    ll res=0;
    for(int tsz=0;tsz<=N;tsz++){
        res=max({res,dp[N-1][tsz][0],dp[N-1][tsz][1]});
    }
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 5676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 428 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 23 ms 5676 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -