Submission #749505

# Submission time Handle Problem Language Result Execution time Memory
749505 2023-05-28T06:28:43 Z farhan132 Catfish Farm (IOI22_fish) C++17
Compilation error
0 ms 0 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;

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

const ll N = 3005;

ll dp[2][2][N], pref[2][2][N], suf[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]] = 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;
  mem(dp[row], 0);
  mem(pref[row], 0);
  mem(suf[row], 0);

  ll ans = 0;

  for(ll i = 0; i < n; i++){
    row ^= 1;
    mem(dp[row], 0);
    mem(pref[row], 0);
    mem(suf[row], 0);
    // 0 -> i-1 > i, i > i+1
    // 1 -> i-1 < i, i < i+1
    for(ll l = 0; l < 2; l++){
        for(ll r = 0; r < 2; r++){
            if(!l && r) continue;
            for(ll j = 0; j < n; j++){
                ll V = 0;
                if(l == 0){
                    V = suf[1-row][l][j] - a[i][j];
                }else{
                    V = pref[1-row][l][j] + (i > 0 ? a[i - 1][j] : 0);
                }
                if(r == 0){
                    V += a[i + 1][j];
                }else{
                    V -= a[i][j];
                }
                dp[row][r][j] = max(dp[row][r][j], V);
                ans = max(ans, V);
            }

        }
    }
    for(ll c = 0; c < 2; c++){
        for(ll j = n - 1; j >= 0; j--){
            suf[row][c][j] = max(suf[row][c][j + 1], dp[row][c][j]);
        }
        for(ll j = 0; j < n; j++){
            pref[row][c][j] = max(dp[row][c][j], (j > 0 ? pref[row][c][j - 1], 0));
        }
    }
  }

  return ans;
}

Compilation message

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:70:77: warning: left operand of comma operator has no effect [-Wunused-value]
   70 |             pref[row][c][j] = max(dp[row][c][j], (j > 0 ? pref[row][c][j - 1], 0));
      |                                                           ~~~~~~~~~~~~~~~~~~^
fish.cpp:70:81: error: expected ':' before ')' token
   70 |             pref[row][c][j] = max(dp[row][c][j], (j > 0 ? pref[row][c][j - 1], 0));
      |                                                                                 ^
      |                                                                                 :
fish.cpp:70:81: error: expected primary-expression before ')' token