Submission #749559

# Submission time Handle Problem Language Result Execution time Memory
749559 2023-05-28T08:13:49 Z farhan132 Catfish Farm (IOI22_fish) C++17
0 / 100
770 ms 152532 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 && r) 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][n];
                        }
                        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][0];
                        }
                        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 714 ms 148612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 71380 KB Output is correct
2 Runtime error 770 ms 152532 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 769 ms 144792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 71372 KB Output is correct
2 Correct 27 ms 71368 KB Output is correct
3 Correct 33 ms 71328 KB Output is correct
4 Correct 27 ms 71280 KB Output is correct
5 Correct 27 ms 71384 KB Output is correct
6 Correct 28 ms 71380 KB Output is correct
7 Correct 29 ms 71296 KB Output is correct
8 Correct 29 ms 71280 KB Output is correct
9 Incorrect 29 ms 71376 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165109154345'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 71372 KB Output is correct
2 Correct 27 ms 71368 KB Output is correct
3 Correct 33 ms 71328 KB Output is correct
4 Correct 27 ms 71280 KB Output is correct
5 Correct 27 ms 71384 KB Output is correct
6 Correct 28 ms 71380 KB Output is correct
7 Correct 29 ms 71296 KB Output is correct
8 Correct 29 ms 71280 KB Output is correct
9 Incorrect 29 ms 71376 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165109154345'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 71372 KB Output is correct
2 Correct 27 ms 71368 KB Output is correct
3 Correct 33 ms 71328 KB Output is correct
4 Correct 27 ms 71280 KB Output is correct
5 Correct 27 ms 71384 KB Output is correct
6 Correct 28 ms 71380 KB Output is correct
7 Correct 29 ms 71296 KB Output is correct
8 Correct 29 ms 71280 KB Output is correct
9 Incorrect 29 ms 71376 KB 1st lines differ - on the 1st token, expected: '216624184325', found: '165109154345'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 769 ms 144792 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 714 ms 148612 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -