Submission #681808

# Submission time Handle Problem Language Result Execution time Memory
681808 2023-01-14T13:11:01 Z Jarif_Rahman Catfish Farm (IOI22_fish) C++17
35 / 100
1000 ms 2097152 KB
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

ll max_weights(int n, int m, vector<int> X, vector<int> Y, vector<int> W){
    vector<vector<ll>> v(n, vector<ll>(n+1, 0));
    for(int i = 0; i < m; i++) v[X[i]][Y[i]+1]+=W[i];

    vector<vector<ll>> dp_up(n, vector<ll>(n+1, 0)), dp_down = dp_up,
    up_to_up = dp_up, down_to_down = dp_up, down_to_up = dp_up;

    vector<vector<ll>> pref(n, vector<ll>(n+1, 0));
    for(int i = 0; i < n; i++) for(int j = 0; j <= n; j++){
        if(j) pref[i][j] = pref[i][j-1];
        pref[i][j]+=v[i][j];
    }

    for(int i = n-1; i >= 0; i--){
        for(int j = 0; j <= n; j++){
            if(i == n-1){
                dp_down[i][j] = 0;
                dp_up[i][j] = 0;
                continue;
            }

            dp_up[i][j]-=pref[i][j];
            ll s = 0;
            for(int k = j; k >= 0; k--){
                if(k < j) s+=v[i+1][k+1];
                dp_down[i][j] = max(dp_down[i][j], s+dp_down[i+1][k]);
            }

            s = 0;
            for(int k = j+1; k <= n; k++) s+=v[i][k];
            dp_up[i][j] = max(dp_up[i][j], s+dp_down[i+1][n]);

            if(i+2 < n){
                s = 0;
                for(int k = 0; k <= j; k++) s+=v[i+1][k];
                for(int k = 0; k <= n; k++){
                    if(k > j) s+=v[i+1][k];
                    dp_down[i][j] = max(dp_down[i][j], s+dp_up[i+2][k]);
                }
                dp_down[i][j] = max(dp_down[i][j], s+dp_down[i+2][n]);
            }
        }

        if(i){
            ll mx = 0;
            for(int j = 0; j <= n; j++) mx = max(mx, pref[i-1][j]+dp_up[i][j]);
            fill(dp_up[i-1].begin(), dp_up[i-1].end(), mx);
        }
    }

    return max(*max_element(dp_up[0].begin(), dp_up[0].end()), *max_element(dp_down[0].begin(), dp_down[0].end()));
}
# Verdict Execution time Memory Grader output
1 Runtime error 802 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 786 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 774 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 10 ms 1492 KB Output is correct
10 Correct 70 ms 5348 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 79 ms 5304 KB Output is correct
13 Correct 3 ms 556 KB Output is correct
14 Correct 74 ms 5332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 10 ms 1492 KB Output is correct
10 Correct 70 ms 5348 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 79 ms 5304 KB Output is correct
13 Correct 3 ms 556 KB Output is correct
14 Correct 74 ms 5332 KB Output is correct
15 Correct 71 ms 5304 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 79 ms 7152 KB Output is correct
18 Correct 84 ms 7128 KB Output is correct
19 Correct 88 ms 7208 KB Output is correct
20 Correct 79 ms 7124 KB Output is correct
21 Correct 76 ms 6996 KB Output is correct
22 Correct 96 ms 8928 KB Output is correct
23 Correct 70 ms 5660 KB Output is correct
24 Correct 75 ms 6500 KB Output is correct
25 Correct 76 ms 5332 KB Output is correct
26 Correct 81 ms 5632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 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 10 ms 1492 KB Output is correct
10 Correct 70 ms 5348 KB Output is correct
11 Correct 10 ms 1492 KB Output is correct
12 Correct 79 ms 5304 KB Output is correct
13 Correct 3 ms 556 KB Output is correct
14 Correct 74 ms 5332 KB Output is correct
15 Correct 71 ms 5304 KB Output is correct
16 Correct 2 ms 596 KB Output is correct
17 Correct 79 ms 7152 KB Output is correct
18 Correct 84 ms 7128 KB Output is correct
19 Correct 88 ms 7208 KB Output is correct
20 Correct 79 ms 7124 KB Output is correct
21 Correct 76 ms 6996 KB Output is correct
22 Correct 96 ms 8928 KB Output is correct
23 Correct 70 ms 5660 KB Output is correct
24 Correct 75 ms 6500 KB Output is correct
25 Correct 76 ms 5332 KB Output is correct
26 Correct 81 ms 5632 KB Output is correct
27 Execution timed out 1120 ms 494252 KB Time limit exceeded
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 774 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 802 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -