Submission #1032998

# Submission time Handle Problem Language Result Execution time Memory
1032998 2024-07-24T11:49:09 Z Mr_Husanboy Catfish Farm (IOI22_fish) C++17
52 / 100
867 ms 2097152 KB
#include "fish.h"
#include <bits/stdc++.h>
 
using namespace std;
 
#define ff first
#define ss second
#define all(a) (a).begin(), (a).end()
#define ll long long
 
template<typename T>
int len(T &a){
    return a.size();
}
 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
 
 
long long max_weights(int n, int m, std::vector<int> x, std::vector<int> y,
                      std::vector<int> w) {
    vector<vector<ll>> s(n + 1, vector<ll> (n + 1));
 
    for(int i = 0; i < m; i ++) s[x[i] + 1][y[i] + 1] = w[i];
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= n; j ++) s[i][j] += s[i][j - 1];
 
    vector<vector<array<ll, 2>>> dp(n + 1, vector<array<ll, 2>>(n + 1));
    for(int j = 0; j <= n; j ++){
        dp[2][j][0] = s[1][j];
    }
    for(int i = 2; i <= n; i ++){
        ll mx = 0;
        ll mx2 = 0;
        vector<ll> suf(n + 1);
        for(int j = n; j >= 0; j --){
            mx2 = max(mx2, max(dp[i - 2][j][0], dp[i - 2][j][1]) + s[i - 1][j]);
            suf[j] = mx2;
        }
        mx2 = 0;
        for(int j = 0; j <= n; j ++){
            mx2 = max({mx2, dp[i - 2][j][0], dp[i - 2][j][1]});
            if(i > 2) dp[i][j][0] = max(mx2 + s[i - 1][j], suf[j]);
            dp[i][j][1] = dp[i][j][0];
            mx = max(mx, dp[i - 1][j][0] - s[i - 1][j]);
            dp[i][j][0] = max(dp[i][j][0], mx + s[i - 1][j]);
        }
        mx = 0;
        for(int j = n; j >= 0; j --){
            mx = max(mx, max(dp[i - 1][j][0], dp[i - 1][j][1]) - (s[i][n] - s[i][j]));
            dp[i][j][1] = max(dp[i][j][1], mx + (s[i][n] - s[i][j]));
        }
    }
    ll ans = 0;
    for(int i = 0; i <= n; i ++){
        ans = max({ans, dp[n][i][0], dp[n][i][1]});
        //cout << dp[n][i][0] << ' ' << dp[n][i][1] << endl;
    }
 
    return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 819 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Runtime error 867 ms 2097152 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 763 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 956 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 956 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 9 ms 4440 KB Output is correct
18 Correct 9 ms 4196 KB Output is correct
19 Correct 9 ms 4296 KB Output is correct
20 Correct 9 ms 4292 KB Output is correct
21 Correct 9 ms 4192 KB Output is correct
22 Correct 17 ms 5960 KB Output is correct
23 Correct 3 ms 2904 KB Output is correct
24 Correct 7 ms 3720 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 3 ms 2916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 956 KB Output is correct
10 Correct 2 ms 2652 KB Output is correct
11 Correct 1 ms 856 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 2 ms 2396 KB Output is correct
15 Correct 2 ms 2392 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 9 ms 4440 KB Output is correct
18 Correct 9 ms 4196 KB Output is correct
19 Correct 9 ms 4296 KB Output is correct
20 Correct 9 ms 4292 KB Output is correct
21 Correct 9 ms 4192 KB Output is correct
22 Correct 17 ms 5960 KB Output is correct
23 Correct 3 ms 2904 KB Output is correct
24 Correct 7 ms 3720 KB Output is correct
25 Correct 2 ms 2396 KB Output is correct
26 Correct 3 ms 2916 KB Output is correct
27 Correct 135 ms 212188 KB Output is correct
28 Correct 50 ms 22408 KB Output is correct
29 Correct 191 ms 224600 KB Output is correct
30 Correct 192 ms 224848 KB Output is correct
31 Correct 196 ms 224736 KB Output is correct
32 Correct 55 ms 19536 KB Output is correct
33 Correct 189 ms 224860 KB Output is correct
34 Correct 197 ms 225104 KB Output is correct
35 Correct 158 ms 216920 KB Output is correct
36 Correct 186 ms 224588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 763 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 819 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -