답안 #629448

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
629448 2022-08-14T13:45:21 Z arnold518 메기 농장 (IOI22_fish) C++17
0 / 100
35 ms 5952 KB
#include "fish.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 3000;
const ll INF = 1e18;

int N, M;
vector<pii> V[MAXN+10];

ll dp1[MAXN+10][MAXN+10], dp2[MAXN+10][MAXN+10], P[MAXN+10];

ll max_weights(int _N, int _M, vector<int> _X, vector<int> _Y, vector<int> _W)
{
    N=_N; M=_M;
    for(int i=0; i<M; i++)
    {
        V[_X[i]+1].push_back({_Y[i]+1, _W[i]});
    }

    for(int i=1; i<=N; i++)
    {
        sort(V[i].begin(), V[i].end());
    }
    
    for(int i=0; i<=N; i++) for(int j=0; j<=N; j++) dp1[i][j]=dp2[i][j]=-INF;
    dp1[0][0]=0; dp2[0][0]=0;

    for(int i=1; i<=N; i++)
    {
        int t=V[i].size()-1;
        P[N]=dp1[i-1][N];
        for(int j=N-1; j>=0; j--)
        {
            int tt=0;
            if(t>=0 && V[i][t].first==j+1) tt=V[i][t--].second;
            P[j]=max(P[j+1], dp1[i-1][j]+tt);
        }
        for(int j=0; j<=N; j++) dp1[i][j]=max(dp2[i-1][j], P[j]);

        ll p=0, q=0;
        t=0;
        for(int j=0; j<=N; j++) 
        {
            int tt=0;
            if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
            p=max(p, dp1[i-1][j]);
            P[j]=max(P[j], p)+tt;
        }
        for(int j=0; j<=N; j++) dp2[i][j]=max(dp2[i][j], P[j]);

        t=0; P[0]=0;
        for(int j=1; j<=N; j++) 
        {
            int tt=0;
            if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
            P[j]=max(P[j-1], dp2[i-1][j]+tt);
        }
        for(int j=0; j<=N; j++) dp2[i][j]=max(dp2[i][j], P[j]);
    }
    return max(dp1[N][0], dp2[N][0]);
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:50:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
      |                ~^~~~~~~~~~~~
fish.cpp:60:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |             if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
      |                ~^~~~~~~~~~~~
fish.cpp:45:17: warning: unused variable 'q' [-Wunused-variable]
   45 |         ll p=0, q=0;
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 5952 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB 1st lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 340 KB 1st lines differ - on the 1st token, expected: '3', found: '2'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 568 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 35 ms 5952 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -