Language: C++

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int field[110][110];
int h, w, ex, ey;
char c;
short dp[101][101][101][101];

int cnt(int il, int ir, int jl, int jr){
    if(il > ir || jl > jr)return 0;
    il--,jl--;
    return field[ir][jr] + field[il][jl] - field[ir][jl] - field[il][jr];
}

int cnti(int il, int ir, int jl, int jr, int i){
    int ill = i, irr = i, jll = jl, jrr= jr;
    ill = max(ill, ir - ex + 1);
    irr = min(irr, il + h -ex);
    jll = max(jll, jr - ey + 1);
    jrr = min(jrr, jl + w - ey);
    return cnt(ill, irr, jll, jrr);
}

int cntj(int il, int ir, int jl, int jr, int j){
    int ill = il, irr = ir, jll = j, jrr= j;
    ill = max(ill, ir - ex + 1);
    irr = min(irr, il + h -ex);
    jll = max(jll, jr - ey + 1);
    jrr = min(jrr, jl + w - ey);
    return cnt(ill, irr, jll, jrr);
}

int main(){
    cin >> h >> w;
    for(int i = 1;i <= h;i++){
        for(int j = 1;j <= w;j++){
            cin >> c;
            if(c == 'o')field[i][j] = 1;
            if(c == 'E')ex = i, ey = j;
            field[i][j] -= field[i-1][j-1] - field[i-1][j] - field[i][j-1];
        }
    }

    for(int iwidth = 0;iwidth <= h;iwidth++){
        for(int jwidth = 0;jwidth <= w;jwidth++){
            for(int il = 1;il+iwidth <= h;il++){
                int ir = il + iwidth;
                for(int jl = 1;jl + jwidth <= w;jl++){
                    int jr = jl + jwidth;
                    int tmp = dp[il][ir][jl][jr];
                    dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1));
                    dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1));
                    dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1));
                    dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1));
                }
            }
        }
    }
    cout << dp[1][h][1][w] << endl;    
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:68:47: error: no matching function for call to 'max(short int&, int)'
   68 |                     dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:68:47: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   68 |                     dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:68:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   68 |                     dp[il-1][ir][jl][jr] = max(dp[il-1][ir][jl][jr], tmp + cnti(il,ir,jl,jr,il-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:69:47: error: no matching function for call to 'max(short int&, int)'
   69 |                     dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:69:47: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   69 |                     dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:69:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   69 |                     dp[il][ir+1][jl][jr] = max(dp[il][ir+1][jl][jr], tmp + cnti(il,ir,jl,jr,ir+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:70:47: error: no matching function for call to 'max(short int&, int)'
   70 |                     dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:70:47: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   70 |                     dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:70:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   70 |                     dp[il][ir][jl-1][jr] = max(dp[il][ir][jl-1][jr], tmp + cntj(il,ir,jl,jr,jl-1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:71:47: error: no matching function for call to 'max(short int&, int)'
   71 |                     dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:71:47: note:   deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
   71 |                     dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:71:47: note:   mismatched types 'std::initializer_list<_Tp>' and 'short int'
   71 |                     dp[il][ir][jl][jr+1] = max(dp[il][ir][jl][jr+1], tmp + cntj(il,ir,jl,jr,jr+1));
      |                                            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~