Submission #629478

# Submission time Handle Problem Language Result Execution time Memory
629478 2022-08-14T14:17:51 Z arnold518 Catfish Farm (IOI22_fish) C++17
52 / 100
276 ms 158380 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;
    for(int i=0; i<=N; i++) dp2[0][i]=0;
    dp1[0][0]=0; dp2[0][0]=0;

    for(int i=1; i<=N+1; 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]+tt, dp1[i-1][j]);
        }
        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]); q+=tt;
            P[j]=max(P[j], p)+q;
        }
        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]+tt, dp2[i-1][j]);
        }
        for(int j=0; j<=N; j++) dp2[i][j]=max(dp2[i][j], P[j]);
    }
/*
    for(int i=1; i<=N; i++)
    {
        for(int j=0; j<=N; j++) printf("%lld ", dp1[i][j]); printf("\n");
    }
    printf("\n");
    for(int i=1; i<=N; i++)
    {
        for(int j=0; j<=N; j++) printf("%lld ", dp2[i][j]); printf("\n");
    }
*/
    return max(dp1[N+1][0], dp2[N+1][0]);
}

Compilation message

fish.cpp: In function 'll max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:51: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]
   51 |             if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
      |                ~^~~~~~~~~~~~
fish.cpp:61: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]
   61 |             if(t<V[i].size() && V[i][t].first==j) tt=V[i][t++].second;
      |                ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 5952 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 67 ms 11144 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 1876 KB Output is correct
10 Correct 4 ms 4316 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 1876 KB Output is correct
10 Correct 4 ms 4316 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 3 ms 1168 KB Output is correct
17 Correct 21 ms 5796 KB Output is correct
18 Correct 16 ms 6036 KB Output is correct
19 Correct 18 ms 5988 KB Output is correct
20 Correct 17 ms 6004 KB Output is correct
21 Correct 17 ms 5972 KB Output is correct
22 Correct 31 ms 7744 KB Output is correct
23 Correct 7 ms 4724 KB Output is correct
24 Correct 16 ms 5696 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Correct 6 ms 4684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 2 ms 1876 KB Output is correct
10 Correct 4 ms 4316 KB Output is correct
11 Correct 2 ms 1876 KB Output is correct
12 Correct 4 ms 4180 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 4 ms 4180 KB Output is correct
15 Correct 3 ms 4180 KB Output is correct
16 Correct 3 ms 1168 KB Output is correct
17 Correct 21 ms 5796 KB Output is correct
18 Correct 16 ms 6036 KB Output is correct
19 Correct 18 ms 5988 KB Output is correct
20 Correct 17 ms 6004 KB Output is correct
21 Correct 17 ms 5972 KB Output is correct
22 Correct 31 ms 7744 KB Output is correct
23 Correct 7 ms 4724 KB Output is correct
24 Correct 16 ms 5696 KB Output is correct
25 Correct 3 ms 4180 KB Output is correct
26 Correct 6 ms 4684 KB Output is correct
27 Correct 140 ms 142004 KB Output is correct
28 Correct 79 ms 27344 KB Output is correct
29 Correct 253 ms 158380 KB Output is correct
30 Correct 276 ms 157848 KB Output is correct
31 Correct 263 ms 157872 KB Output is correct
32 Correct 111 ms 26364 KB Output is correct
33 Correct 252 ms 157860 KB Output is correct
34 Correct 235 ms 157244 KB Output is correct
35 Correct 182 ms 147688 KB Output is correct
36 Correct 261 ms 156716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 468 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 5952 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -