Submission #628344

# Submission time Handle Problem Language Result Execution time Memory
628344 2022-08-13T10:41:48 Z guangxuan Catfish Farm (IOI22_fish) C++17
52 / 100
800 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
typedef long long ll;

const ll INF= 1LL<<60;
using namespace std;

long long max_weights(int N, int M, std::vector<int> X, vector<int> Y,
                      vector<int> W) {
    for(int i=0;i<M;i++){
        Y[i]+=1;
    }
    ll rs[N+1][N+1]={};
    for(int i=0;i<M;i++){
        rs[X[i]][Y[i]]+=W[i];
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            rs[i][j+1]+=rs[i][j];
        }
    }
    ll dp[N][3][N+1]; // (0, h[i-1]), (h[i-1] <= h[i], h[i]), (h[i-1]>h[i], h[i])
    memset(dp,0,sizeof dp);
    for(int i=0;i<=N;i++){
        dp[1][0][i]=rs[1][i];
        dp[1][1][i]=rs[0][i];
        dp[1][2][i]=rs[1][N]-rs[1][i];
    }
    for(int i=2;i<N;i++){
        for(int j=0;j<=N;j++){
            dp[i][0][j]=max(dp[i-1][1][j],dp[i-1][2][j])+rs[i][j];
        }
        //0,k -> 1,j
        ll cmax = -INF;
        for(int j=0;j<=N;j++){
            cmax = max(cmax,dp[i-1][0][j]+rs[i-1][j]);
            dp[i][1][j]=max(dp[i][1][j],cmax-rs[i-1][j]);
        }
        cmax = -INF;
        for(int j=N;j>=0;j--){
            cmax = max(cmax,dp[i-1][0][j]);
            dp[i][1][j]=max(dp[i][1][j],cmax);
        }
        //1,k -> 1,j
        cmax = -INF;
        for(int j=0;j<=N;j++){
            cmax = max(cmax, dp[i-1][1][j]-rs[i-1][j]);
            dp[i][1][j]=max(dp[i][1][j],cmax+rs[i-1][j]);
        }
        //1,k 2,k -> 2,j
        cmax = -INF;
        for(int j=N-1;j>=0;j--){
            cmax = max(cmax, max(dp[i-1][1][j+1],dp[i-1][2][j+1])+rs[i][j+1]);
            dp[i][2][j]=max(dp[i][2][j],cmax-rs[i][j]);
        }
    }
    ll ans = 0;
    /*for(int i=0;i<=N;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<=N;k++){
                cout << dp[i][j][k] << ' ';
            }
            cout << endl;
        }
        cout << endl;
    }*/
    for(int j=0;j<3;j++)
        for(int k=0;k<=N;k++)ans = max(ans, dp[N-1][j][k]);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 800 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 767 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 747 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 3 ms 3156 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 3 ms 3156 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 5 ms 3028 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 16 ms 4912 KB Output is correct
18 Correct 14 ms 5072 KB Output is correct
19 Correct 14 ms 4920 KB Output is correct
20 Correct 14 ms 4908 KB Output is correct
21 Correct 14 ms 4884 KB Output is correct
22 Correct 33 ms 6712 KB Output is correct
23 Correct 5 ms 3412 KB Output is correct
24 Correct 11 ms 4308 KB Output is correct
25 Correct 3 ms 3156 KB Output is correct
26 Correct 4 ms 3360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 980 KB Output is correct
10 Correct 3 ms 3156 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 3 ms 3028 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 2 ms 3028 KB Output is correct
15 Correct 5 ms 3028 KB Output is correct
16 Correct 1 ms 480 KB Output is correct
17 Correct 16 ms 4912 KB Output is correct
18 Correct 14 ms 5072 KB Output is correct
19 Correct 14 ms 4920 KB Output is correct
20 Correct 14 ms 4908 KB Output is correct
21 Correct 14 ms 4884 KB Output is correct
22 Correct 33 ms 6712 KB Output is correct
23 Correct 5 ms 3412 KB Output is correct
24 Correct 11 ms 4308 KB Output is correct
25 Correct 3 ms 3156 KB Output is correct
26 Correct 4 ms 3360 KB Output is correct
27 Correct 234 ms 282332 KB Output is correct
28 Correct 75 ms 25740 KB Output is correct
29 Correct 307 ms 291628 KB Output is correct
30 Correct 312 ms 291648 KB Output is correct
31 Correct 353 ms 291636 KB Output is correct
32 Correct 86 ms 18496 KB Output is correct
33 Correct 329 ms 291716 KB Output is correct
34 Correct 313 ms 291032 KB Output is correct
35 Correct 245 ms 285004 KB Output is correct
36 Correct 318 ms 289596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 747 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 800 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -