Language: C++

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;


int main(){

    int h,w;
    cin >> h >> w;

    vector<vector<int>> red(h);
    vector<vector<int>> blue(h);

    rep(i,h){
        rep(j, w){
            int tmp;
            cin >> tmp;

            red[i].pback(tmp);
        }
    }

    rep(i,h){
        rep(j, w){
            int tmp;
            cin >> tmp;

            blue[i].pback(tmp);
        }
    }

    bool dp[h][w][2][12801] = {};
    int ans = 6401;

    dp[0][0][0][6400] = true;
    dp[0][0][1][6400] = true;
    int count = 0;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            for(int k = 0; k <= 12800; k++){
                count++;
                if(i == h - 1 && j == w - 1){
                    int tmp1 = k + red[i][j] - blue[i][j] - 6400;
                    int tmp2 = k - red[i][j] + blue[i][j] - 6400;
                    ans = min(ans, min(abs(tmp1), abs(tmp2)));
                }else{
                    if(dp[i][j][0][k]){
                        if(i != h - 1){
                            dp[i + 1][j][0][k + red[i][j] - blue[i][j]] = true;
                            dp[i + 1][j][1][k + red[i][j] - blue[i][j]] = true;
                        }
                        if(j != w - 1){
                            dp[i][j + 1][0][k + red[i][j] - blue[i][j]] = true;
                            dp[i][j + 1][1][k + red[i][j] - blue[i][j]] = true;
                        }
                    }

                    if(dp[i][j][1][k]){
                        if(i != h - 1){
                            dp[i + 1][j][0][k - red[i][j] + blue[i][j]] = true;
                            dp[i + 1][j][1][k - red[i][j] + blue[i][j]] = true;
                        }
                        if(j != w - 1){
                            dp[i][j + 1][0][k - red[i][j] + blue[i][j]] = true;
                            dp[i][j + 1][1][k - red[i][j] + blue[i][j]] = true;
                        }
                    }

                    if(dp[i][j][1][k]){
                        if(i != h - 1) dp[i + 1][j][k + red[i][j] - blue[i][j]] = true;
                        if(j != w - 1) dp[i][j + 1][k + red[i][j] - blue[i][j]] = true;
                    }
                }
            }
        }
    }

    cerr << count << endl;

    cout << ans << endl;

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:81:81: error: incompatible types in assignment of 'bool' to 'bool [12801]'
   81 |                         if(i != h - 1) dp[i + 1][j][k + red[i][j] - blue[i][j]] = true;
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
a.cc:82:81: error: incompatible types in assignment of 'bool' to 'bool [12801]'
   82 |                         if(j != w - 1) dp[i][j + 1][k + red[i][j] - blue[i][j]] = true;
      |                                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~