Submission #749576

# Submission time Handle Problem Language Result Execution time Memory
749576 2023-05-28T08:55:14 Z farhan132 Catfish Farm (IOI22_fish) C++17
52 / 100
798 ms 152876 KB
#include "fish.h"
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef double dd;
typedef pair<ll , ll> ii;
typedef tuple < ll,  ll, ll > tp;

const ll INF = (ll)1e18;

#define mem(a , b) memset(a, b ,sizeof(a))

const ll N = 3005;

ll dp[2][2][2][N], pref[2][2][2][N], suf[2][2][2][N];
ll a[N][N]; ll n;

long long max_weights(int _n, int m, std::vector<int> X, std::vector<int> Y,
                      std::vector<int> W) {
  n = _n;
  mem(a, 0); mem(dp, 0); mem(pref, 0);
  for(ll i = 0; i < m; i++){
    a[X[i]][Y[i] + 1] = W[i];
  }
  for(ll i = 0; i < n; i++){
    for(ll j = 1; j <= n; j++){
        a[i][j] += a[i][j - 1];
    }
  }
  ll row = 0;

  ll ans = 0;

  for(ll i = 0; i < n; i++){
    row ^= 1; 
    // 0 -> i-1 > i, i > i+1
    // 1 -> i-1 < i, i < i+1

    // 0 -> sz[i-1] < sz[i], sz[i] < sz[i+1]
    // 1 -> sz[i-1] > sz[i], sz[i] > sz[i+1] 
    for(ll j = 0; j <= n; j++){
        for(ll c = 0; c < 2; c++)
            dp[row][c][0][j] = dp[row][c][1][j] = -INF; 
    }
    for(ll l = 0; l < 2; l++){
        for(ll d1 = 0; d1 < 2; d1++){
            for(ll r = 0; r < 2; r++){
                for(ll d2 = 0; d2 < 2; d2++){
                    if((!l && d1) && (r && !d2)) continue;
                    for(ll j = 0; j <= n; j++){
                        ll V = 0;
                        if(l == 0 && d1){
                            V = suf[1-row][l][d1][j] - a[i][j];
                        }else if(l == 0){
                            V = pref[1-row][l][d1][j];
                        }
                        if(l == 1 && !d1){
                            V = pref[1-row][l][d1][j] + (i > 0 ? a[i - 1][j] : 0);
                        }else if(l == 1){
                            V = suf[1-row][l][d1][j];
                        }
                        if(r == 0 && d2){
                            V += a[i + 1][j];
                        }
                        if(r == 1 && !d2){
                            V -= a[i][j];
                        }
                        dp[row][r][d2][j] = max(dp[row][r][d2][j], V);
                        ans = max(ans, V);
                    }
                }
            }
        }
    }
    // cout << i << ' ' << ans << '\n';
    for(ll c = 0; c < 2; c++){
        for(ll d = 0; d < 2; d++){
            for(ll j = n; j >= 0; j--){
                suf[row][c][d][j] = max(suf[row][c][d][j + 1], dp[row][c][d][j]);
            }
            for(ll j = 0; j <= n; j++){
                pref[row][c][d][j] = max(dp[row][c][d][j], (j > 0 ? pref[row][c][d][j - 1]: -INF));
            }
        }
    }
  }

  return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 726 ms 148908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 71296 KB Output is correct
2 Runtime error 787 ms 152876 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 798 ms 144872 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 71320 KB Output is correct
2 Correct 31 ms 71380 KB Output is correct
3 Correct 28 ms 71372 KB Output is correct
4 Correct 29 ms 71320 KB Output is correct
5 Correct 28 ms 71380 KB Output is correct
6 Correct 28 ms 71388 KB Output is correct
7 Correct 30 ms 71348 KB Output is correct
8 Correct 34 ms 71372 KB Output is correct
9 Correct 41 ms 71408 KB Output is correct
10 Correct 45 ms 71480 KB Output is correct
11 Correct 34 ms 71372 KB Output is correct
12 Correct 38 ms 71444 KB Output is correct
13 Correct 39 ms 71488 KB Output is correct
14 Correct 38 ms 71372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 71320 KB Output is correct
2 Correct 31 ms 71380 KB Output is correct
3 Correct 28 ms 71372 KB Output is correct
4 Correct 29 ms 71320 KB Output is correct
5 Correct 28 ms 71380 KB Output is correct
6 Correct 28 ms 71388 KB Output is correct
7 Correct 30 ms 71348 KB Output is correct
8 Correct 34 ms 71372 KB Output is correct
9 Correct 41 ms 71408 KB Output is correct
10 Correct 45 ms 71480 KB Output is correct
11 Correct 34 ms 71372 KB Output is correct
12 Correct 38 ms 71444 KB Output is correct
13 Correct 39 ms 71488 KB Output is correct
14 Correct 38 ms 71372 KB Output is correct
15 Correct 40 ms 71372 KB Output is correct
16 Correct 38 ms 71372 KB Output is correct
17 Correct 48 ms 73248 KB Output is correct
18 Correct 46 ms 73144 KB Output is correct
19 Correct 47 ms 73196 KB Output is correct
20 Correct 46 ms 73228 KB Output is correct
21 Correct 46 ms 73168 KB Output is correct
22 Correct 64 ms 74724 KB Output is correct
23 Correct 37 ms 71628 KB Output is correct
24 Correct 43 ms 72576 KB Output is correct
25 Correct 35 ms 71404 KB Output is correct
26 Correct 37 ms 71700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 71320 KB Output is correct
2 Correct 31 ms 71380 KB Output is correct
3 Correct 28 ms 71372 KB Output is correct
4 Correct 29 ms 71320 KB Output is correct
5 Correct 28 ms 71380 KB Output is correct
6 Correct 28 ms 71388 KB Output is correct
7 Correct 30 ms 71348 KB Output is correct
8 Correct 34 ms 71372 KB Output is correct
9 Correct 41 ms 71408 KB Output is correct
10 Correct 45 ms 71480 KB Output is correct
11 Correct 34 ms 71372 KB Output is correct
12 Correct 38 ms 71444 KB Output is correct
13 Correct 39 ms 71488 KB Output is correct
14 Correct 38 ms 71372 KB Output is correct
15 Correct 40 ms 71372 KB Output is correct
16 Correct 38 ms 71372 KB Output is correct
17 Correct 48 ms 73248 KB Output is correct
18 Correct 46 ms 73144 KB Output is correct
19 Correct 47 ms 73196 KB Output is correct
20 Correct 46 ms 73228 KB Output is correct
21 Correct 46 ms 73168 KB Output is correct
22 Correct 64 ms 74724 KB Output is correct
23 Correct 37 ms 71628 KB Output is correct
24 Correct 43 ms 72576 KB Output is correct
25 Correct 35 ms 71404 KB Output is correct
26 Correct 37 ms 71700 KB Output is correct
27 Correct 630 ms 71644 KB Output is correct
28 Correct 127 ms 78084 KB Output is correct
29 Correct 693 ms 80936 KB Output is correct
30 Correct 711 ms 81100 KB Output is correct
31 Correct 719 ms 79820 KB Output is correct
32 Correct 128 ms 79628 KB Output is correct
33 Correct 693 ms 79808 KB Output is correct
34 Correct 684 ms 79792 KB Output is correct
35 Correct 670 ms 75468 KB Output is correct
36 Correct 686 ms 79824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 798 ms 144872 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 726 ms 148908 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -