Language: C++

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
using namespace std;
int DP[60][30][60][30], w, h;
const int INF = (1e9);
char S[60][30];
struct state{int lx, ly, rx, ry;};
bool operator<(const state &x, const state &y){ return x.lx < y.lx;}

bool in_range(int a, int b){ return a >= 0 && a < b;}

int solve(){
  priority_queue< pair<int, state> > wait;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(S[i][j] == 'S'){
        wait.emplace(0,(state){i,j,-1,-1});
        wait.emplace(0,(state){-1,-1,i,j});
      }
    }
  }
  while(!wait.empty()){
    state s = wait.top().second;
    int t = -wait.top().first, lx = s.lx, ly = s.ly, rx = s.rx, ry = s.ry;
    wait.pop();
    //printf("%d %d %d %d %d\n",lx,ly,rx,ry,t);
    if(lx >= 0 && rx >= 0 && DP[s.lx][s.ly][s.rx][s.ry] < t) continue;
    if(lx >= 0 && ly >= 0){
      for(int i = -2; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
          int rx_ = lx + i, ry_ = ly + j + 1;
          if((!in_range(rx_,h)) || (!in_range(ry_,w)) ||
             (abs(j)+abs(i) > 2) || (S[rx_][ry_] == 'X')) continue;
          int t_;
          if(S[rx_][ry_] > '9' || S[rx_][ry_] < '0') t_ = t;
          else t_ = t + S[rx_][ry_] - '0';
          if(t_ >= DP[lx][ly][rx_][ry_]) continue;
          DP[lx][ly][rx_][ry_] = t_;
          wait.emplace(-t_,(state){lx,ly,rx_,ry_});
        }
      }
    }
    if(rx >= 0 && ry >= 0){
      for(int i = -2; i < 3; ++i){
        for(int j = 0; j < 3; ++j){
          int lx_ = rx + i, ly_ = ry - j - 1;
          if((!in_range(lx_,h)) || (!in_range(ly_,w)) ||
             (abs(j)+abs(i) > 2) || (S[lx_][ly_] == 'X')) continue;
          int t_;
          if(S[lx_][ly_] > '9' || S[lx_][ly_] < '0') t_ = t;
          else t_ = t + S[lx_][ly_] - '0';
          if(t_ >= DP[lx_][ly_][rx][ry]) continue;
          DP[lx_][ly_][rx][ry] = t_;
          wait.emplace(-t_,(state){lx_,ly_,rx,ry});
        }
      }
    }
  }
  //  cout << "while loop finished" << endl;
  int ret = INF;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      if(S[i][j] != 'T') continue;
      for(int k = 0; k < h; ++k)
        for(int l = 0; l < w; ++l)
          ret = min({ret, DP[i][j][k][l], DP[k][l][i][j]});
    }
  }
  return ret;
}

int main(){
  while(cin >> w >> h, w){
    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j)
        cin >> S[i][j];
    for(int i = 0; i < h; ++i)
      for(int j = 0; j < w; ++j)
        for(int k = 0; k < h; ++k)
          for(int l = 0; l < w; ++l)
            DP[i][j][k][l] = INF;
    int ans = solve();
    if(ans >= INF) ans = -1;
    cout << ans << endl;
  }
  return 0;
}



Compiler output:
a.cc: In function 'int solve()':
a.cc:68:20: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   68 |           ret = min({ret, DP[i][j][k][l], DP[k][l][i][j]});
      |                 ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:   candidate expects 2 arguments, 1 provided
/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, 1 provided