Language: C++

#include <bits/stdc++.h>
using namespace std;

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

int m,n,a[100][100],memo[100][100][101];

int DFS(int y,int l,int r){
	if(y==m) return 0;
	int &res=memo[y][l][r];
	if(res!=-1) return res;
	if(l==r) return res=DFS(y+1,0,n);

	res=max(res,DFS(y,l+1,r)+(a[y][l]+(y>0)+(l==0?0:1)+((r!=n)&&(r-l==1)))%2);
	res=max(res,DFS(y,l,r-1)+(a[y][r-1]+(y>0)+(r==n?0:1)+((l!=0)&&(r-l==1)))%2);
	return res;
}

void Solve(){
	cin >> m >> n;
	rep(i,0,m) rep(j,0,n) cin >> a[i][j];

	fill_n(memo,100*100*101,-1);
	cout << DFS(0,0,n) << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Compiler output:
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h: In instantiation of 'typename __gnu_cxx::__enable_if<std::__is_scalar<_Tp>::__value, void>::__type std::__fill_a1(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = int (*)[100][101]; _Tp = int; typename __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type = void]':
/usr/include/c++/14/bits/stl_algobase.h:998:21:   required from 'void std::__fill_a(_FIte, _FIte, const _Tp&) [with _FIte = int (*)[100][101]; _Tp = int]'
  998 |     { std::__fill_a1(__first, __last, __value); }
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1154:20:   required from '_OutputIterator std::__fill_n_a(_OutputIterator, _Size, const _Tp&, random_access_iterator_tag) [with _OutputIterator = int (*)[100][101]; _Size = int; _Tp = int]'
 1154 |       std::__fill_a(__first, __first + __n, __value);
      |       ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:1183:29:   required from '_OI std::fill_n(_OI, _Size, const _Tp&) [with _OI = int (*)[100][101]; _Size = int; _Tp = int]'
 1183 |       return std::__fill_n_a(__first, std::__size_to_integer(__n), __value,
      |              ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1184 |                                std::__iterator_category(__first));
      |                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:50:8:   required from here
   50 |         fill_n(memo,100*100*101,-1);
      |         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:952:18: error: incompatible types in assignment of 'const int' to 'int [100][101]'
  952 |         *__first = __tmp;
      |         ~~~~~~~~~^~~~~~~