Language: C++

#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#define INT long long
#define MOD 1000000007
#define oo 1987654321

using namespace std;
INT h, w, dt[302][302][302];
string a[400];
INT dp(int x, int y, int z)
{
    if( x>h or y>h or z>h) return oo;
    if(x == h && y == h && z == h) return 0;
    if( ~dt[x][y][z] ) return dt[x][y][z];
    INT &ret = dt[x][y][z] = oo;
    ret = min( ret, dp(x+1, y, z) + (y>x||y==h)?0:(bool)(a[0][0]==a[x-y][1])) );
    ret = min( ret, dp(x, y+1, z) +
              (x>y||x==h)?0:(bool)(a[0][1]==a[y-x][0])) + (z>y||z==h)?0:(bool)(a[0][1]==a[y-z][2])) ) ;
    ret = min( ret, dp(x, y, z+1) + (y>z||y==h)?0:(bool)(a[0][2]==a[z-y][1])) );
    return ret;
}
int main()
{
    ios::sync_with_stdio(false);
    memset(dt, -1, sizeof(dt));
    cin>>h>>w;
    for(int i = 0 ; i < h ; i++) cin>>a[i];
    if( w == 3 )
        cout<<dp(0, 0, 0)<<endl;
    else
        cout<<-1<<endl;
    return 0;
}


Compiler output:
a.cc: In function 'long long int dp(int, int, int)':
a.cc:24:14: error: no matching function for call to 'min(long long int&, int)'
   24 |     ret = min( ret, dp(x+1, y, z) + (y>x||y==h)?0:(bool)(a[0][0]==a[x-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:24:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   24 |     ret = min( ret, dp(x+1, y, z) + (y>x||y==h)?0:(bool)(a[0][0]==a[x-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:24:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   24 |     ret = min( ret, dp(x+1, y, z) + (y>x||y==h)?0:(bool)(a[0][0]==a[x-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:25:14: error: no matching function for call to 'min(long long int&, int)'
   25 |     ret = min( ret, dp(x, y+1, z) +
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
   26 |               (x>y||x==h)?0:(bool)(a[0][1]==a[y-x][0])) + (z>y||z==h)?0:(bool)(a[0][1]==a[y-z][2])) ) ;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:25:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   25 |     ret = min( ret, dp(x, y+1, z) +
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
   26 |               (x>y||x==h)?0:(bool)(a[0][1]==a[y-x][0])) + (z>y||z==h)?0:(bool)(a[0][1]==a[y-z][2])) ) ;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:25:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   25 |     ret = min( ret, dp(x, y+1, z) +
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~
   26 |               (x>y||x==h)?0:(bool)(a[0][1]==a[y-x][0])) + (z>y||z==h)?0:(bool)(a[0][1]==a[y-z][2])) ) ;
      |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:27:14: error: no matching function for call to 'min(long long int&, int)'
   27 |     ret = min( ret, dp(x, y, z+1) + (y>z||y==h)?0:(bool)(a[0][2]==a[z-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:27:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   27 |     ret = min( ret, dp(x, y, z+1) + (y>z||y==h)?0:(bool)(a[0][2]==a[z-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:27:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   27 |     ret = min( ret, dp(x, y, z+1) + (y>z||y==h)?0:(bool)(a[0][2]==a[z-y][1])) );
      |           ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~