Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 101;
int n, m;
string a[N];
short int dp[N][N][N][N];
void upd(int &a, int b) {
    a = max(a, b);
}   

int pref[N][N];

int lx_, ly_, rx_, ry_;

int sum(int x1, int y1, int x2, int y2) {

    x1 = max(x1, lx_);
    y1 = max(y1, ly_);
    x2 = min(x2, rx_);
    y2 = min(y2, ry_);

    if (x2 < x1 || y2 < y1)
        return 0;

    return pref[x2 + 1][y2 + 1] - pref[x2 + 1][y1] - pref[x1][y2 + 1] + pref[x1][y1];
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n >> m;
    int Ex, Ey;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < m; ++j) {
            if (a[i][j] == 'E') {   
                Ex = i;
                Ey = j;
            }
        }   
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            pref[i + 1][j + 1] = pref[i + 1][j] + pref[i][j + 1] - pref[i][j] + (a[i][j] == 'o');
        }   
    }   
    int ans = 0;
    for (int lx = n - 1; lx >= 0; --lx) {
        for (int ly = m - 1; ly >= 0; --ly) {
            for (int rx = lx; rx < n; ++rx) {
                for (int ry = ly; ry < m; ++ry) {

                    lx_ = rx - Ex;
                    ly_ = ry - Ey;
                    rx_ = lx + (n - 1 - Ex);
                    ry_ = ly + (m - 1 - Ey);

                    int cur = dp[lx][ly][rx][ry];
                    upd(ans, cur);
                    if (lx) {
                        int cnt = sum(lx - 1, ly, lx - 1, ry);
                        upd(dp[lx - 1][ly][rx][ry], cur + cnt);
                    }   
                    if (ly) {
                        int cnt = sum(lx, ly - 1, rx, ly - 1);
                        upd(dp[lx][ly - 1][rx][ry], cur + cnt);
                    }   
                    if (rx + 1 < n) {
                        int cnt = sum(rx + 1, ly, rx + 1, ry);
                        upd(dp[lx][ly][rx + 1][ry], cur + cnt);
                    }   
                    if (ry + 1 < m) {
                        int cnt = sum(lx, ry + 1, rx, ry + 1);
                        upd(dp[lx][ly][rx][ry + 1], cur + cnt);
                    }   
                }   
            }   
        }   
    }   
    cout << ans << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:75:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int'
   75 |                         upd(dp[lx - 1][ly][rx][ry], cur + cnt);
      |                             ~~~~~~~~~~~~~~~~~~~~~^
a.cc:16:15: note:   initializing argument 1 of 'void upd(int&, int)'
   16 | void upd(int &a, int b) {
      |          ~~~~~^
a.cc:79:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int'
   79 |                         upd(dp[lx][ly - 1][rx][ry], cur + cnt);
      |                             ~~~~~~~~~~~~~~~~~~~~~^
a.cc:16:15: note:   initializing argument 1 of 'void upd(int&, int)'
   16 | void upd(int &a, int b) {
      |          ~~~~~^
a.cc:83:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int'
   83 |                         upd(dp[lx][ly][rx + 1][ry], cur + cnt);
      |                             ~~~~~~~~~~~~~~~~~~~~~^
a.cc:16:15: note:   initializing argument 1 of 'void upd(int&, int)'
   16 | void upd(int &a, int b) {
      |          ~~~~~^
a.cc:87:50: error: cannot bind non-const lvalue reference of type 'int&' to a value of type 'short int'
   87 |                         upd(dp[lx][ly][rx][ry + 1], cur + cnt);
      |                             ~~~~~~~~~~~~~~~~~~~~~^
a.cc:16:15: note:   initializing argument 1 of 'void upd(int&, int)'
   16 | void upd(int &a, int b) {
      |          ~~~~~^