Language: C++

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cassert>
using namespace std;
#define NORTH 0
#define EAST  2
#define SOUTH 1
#define WEST 3
#define INF (1 << 29)
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};
int for_waitcost[]={1,1,0,0};
long long   cost[4][105][105];//101*0 node means the start.101*1node meand goal node
string test[4]={"NORTH","SOUTH","EAST","WEST"};
class edge{
public:
  int cost,tox,toy,d;
};
class signal{
public:
  int total,ns,we;
  bool signal;
  int wait_cost(int check,int nowcost){
    int ret = 0;
    if (check ==1){//cûüÉiÞÆ«
      if (signal == 0){//ÅÉißéÌªcûüÌ
	if ( nowcost%total < ns);
	else ret=total-nowcost%total;
      }else if (signal == 1){//ÅÉißéÌª¡ûüÌ
	if ( nowcost%total >=we);
	else ret=we- nowcost%total;
      }
    }else if (check == 0){//¡ûüÉiÞÆ«
      if (signal == 0){//ÅÉißéÌªcûüÌÆ«
	if ( nowcost%total >=ns);
	else ret = ns-nowcost%total;
      }else if (signal == 1){//ÅÉißéÌª¡ûüÌ
	if ( nowcost%total <we);
	else ret=total-nowcost%total;
      }
    }
    assert(ret >=0);
    return ret;
  }
};

class state{
public:
  int x,y,d;
  long long cost;
  bool operator<(const state & a)const{
    return cost > a.cost;
  }
};
signal inform[105][105];
vector<edge> Edge[105][105];
bool flag;//0 goal/start is in ns,1 goal/start is in we
void reset(int,int);
int b_search(int *,int *,int);
int dijkstra(state ini){
  priority_queue<state> Q;
  Q.push(ini);
  //cout << "ini " << ini.x << " " << ini.y << " " << cost[0][1][4] << endl;
  int ans = INF;
  cost[ini.d][ini.y][ini.x]=0;
  while(!Q.empty()){
    state now = Q.top();
    Q.pop();
    if (now.y == 1 && now.x == 104)return ans=min(ans,now.cost);//return now.cost;
    for(int i=0;i<Edge[now.y][now.x].size();i++){
      int next = now.cost+Edge[now.y][now.x][i].cost;
      edge check=Edge[now.y][now.x][i];
      if( Edge[now.y][now.x][i].tox == 104);
      else {
	next += inform[check.toy][check.tox].wait_cost(for_waitcost[check.d],next);
      }
      
      if ( next < cost[check.d][check.toy][check.tox] ){
	cost[check.d][check.toy][check.tox]=next;
	state ins = {check.tox,check.toy,check.d,next};
	Q.push(ins);
      }
    }
  }
  return ans;
  return -1;
}

main(){
  int column,row;
  while(cin >> column >> row && column){
    reset(column,row);
    int distancec[column+10],distancer[row+10];
    for(int i=0;i<column-1;i++)cin >> distancec[i];
    for(int i=0;i<row-1;i++)cin >> distancer[i];
    distancer[row-1]=distancer[row-2];
    distancec[column-1]=distancec[column-2];
    //connect column
    for(int i=0;i<row;i++){
      for(int j=0;j<column-1;j++){
	edge ins={distancec[j],j+1,i,EAST};
	edge ins2={distancec[j],j,i,WEST};
	Edge[i][j].push_back(ins);
	Edge[i][j+1].push_back(ins2);
      }
    }
    
    for(int i=0;i<column;i++){
      for(int j=0;j<row-1;j++){
	edge ins={distancer[j],i,j+1,NORTH};
	edge ins2={distancer[j],i,j,SOUTH};	
	Edge[j][i].push_back(ins);
	Edge[j+1][i].push_back(ins2);
      }
    }
    //signal information
    for(int i=0;i<row;i++){
      for(int j=0;j<column;j++){
	cin >> inform[i][j].ns >> inform[i][j].we>>inform[i][j].signal;
	inform[i][j].total=inform[i][j].ns+inform[i][j].we;
      }
    }
    //start and goal information;
    int sx,sy,gx,gy;
    int spointx,spointy,gpointx,gpointy,direction=0;
    int tempsx,tempsy,tempgx,tempgy;
    cin >> sx >> sy >> gx >> gy;
    tempsx=sx,tempgx=gx,tempsy=sy,tempgy=sy;
    if ( sx == gx && sy == gy){cout << 0 << endl;continue;}
    //connect node 101 with spointx,spointx+1
    //make start node information
    flag = 0;
    spointx=b_search(distancec,&sx,column-1);
    if ( flag == 1)direction = 0;//X^[gª½ûü
    else direction =1;//X^[gª¼ûü
    spointy=b_search(distancer,&sy,row-1);
    if ( direction == 0){//¼ûüÉißé
      edge ins = {sy,spointx,spointy,SOUTH};
      edge ins2= {sy,104,0,NORTH};
      edge ins3={distancer[spointy+1]-sy,spointx,spointy+1,NORTH};
      edge ins4={distancer[spointy+1]-sy,104,0,SOUTH};
      Edge[0][104].push_back(ins);
      Edge[0][104].push_back(ins3);
      Edge[spointy][spointx].push_back(ins2);
      Edge[spointy+1][spointx].push_back(ins4);
      assert(distancer[spointy+1]-sy >=0);
    }else if (direction == 1){//½ûüÉißé
      edge ins={sx,spointx,spointy,WEST};
      edge ins2={sx,104,0,EAST};
      edge ins3={distancec[spointx+1]-sx,spointx+1,spointy,EAST};
      edge ins4={distancec[spointx+1]-sx,104,0,WEST};
      Edge[0][104].push_back(ins);
      Edge[0][104].push_back(ins3);
      Edge[spointy][spointx].push_back(ins2);
      Edge[spointy][spointx+1].push_back(ins4);
      assert(distancec[spointx+1]-sx >=0);
    }
    
    
    
    //make end information;
    flag = 0;
    gpointx=b_search(distancec,&gx,column-1);
    if (flag == 1)direction = 0;
    else direction = 1;
    gpointy=b_search(distancer,&gy,row-1);
    if ( direction == 0){//¼ûüÉißé
      edge ins = {gy,gpointx,gpointy,SOUTH};
      edge ins2={gy,104,1,NORTH};
      edge ins3={distancer[gpointy+1]-gy,gpointx,gpointy+1,NORTH};
      edge ins4={distancer[gpointy+1]-gy,104,1,SOUTH};
      Edge[1][104].push_back(ins);
      Edge[1][104].push_back(ins3);
      Edge[gpointy][gpointx].push_back(ins2);
      Edge[gpointy+1][gpointx].push_back(ins4);
      assert(distancer[gpointy+1]-gy >=0);
    }else if (direction == 1){
      edge ins={gx,gpointx,gpointy,WEST};
      edge ins2={gx,104,1,EAST};
      edge ins3={distancec[gpointx+1]-gx,gpointx+1,gpointy,EAST};
      edge ins4={distancec[gpointx+1]-gx,104,1,WEST};
      Edge[1][104].push_back(ins);
      Edge[1][104].push_back(ins3);
      Edge[gpointy][gpointx].push_back(ins2);
      Edge[gpointy][gpointx+1].push_back(ins4);
      assert(distancec[gpointx+1]-gx >=0);
    }
    //cout << spointx << " " << spointy << " " << gpointx << " " << gpointy << endl;
    if (spointx == gpointx && gpointy == spointy){
      cout << max(sx,gx)-min(sx,gx)+max(sy,gy)-min(sy,gy)<<endl;;
      continue;
    }
    
    state ini={104,0,0,0};
    cout << dijkstra(ini) << endl;
  }
  return 0;
}

int b_search(int *a,int *find,int n){
  int total=0;
  for(int i=0;i<n+1;i++){
    if ( total < *find && *find < total+a[i]){*find-=total;return i;}
    if ( total == *find ){*find-=total;flag = 1;return i;}
    total+=a[i];
  }
  return -1;
}

void reset(int w,int h){
  for(int i=0;i<105;i++){
    for(int j=0;j<105;j++){
      Edge[i][j].clear();
      for(int k=0;k<4;k++){
	cost[k][i][j]=INF;
      }
    }
  }
  for(int i=0;i<4;i++){
    cost[i][0][104]=INF;
    cost[i][1][104]=INF;
  }
  Edge[0][104].clear();
  Edge[1][104].clear();
}

Compiler output:
a.cc: In function 'int dijkstra(state)':
a.cc:71:50: error: no matching function for call to 'min(int&, long long int&)'
   71 |     if (now.y == 1 && now.x == 104)return ans=min(ans,now.cost);//return now.cost;
      |                                               ~~~^~~~~~~~~~~~~~
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:   template argument deduction/substitution failed:
a.cc:71:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   71 |     if (now.y == 1 && now.x == 104)return ans=min(ans,now.cost);//return now.cost;
      |                                               ~~~^~~~~~~~~~~~~~
/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:71:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   71 |     if (now.y == 1 && now.x == 104)return ans=min(ans,now.cost);//return now.cost;
      |                                               ~~~^~~~~~~~~~~~~~
a.cc: At global scope:
a.cc:91:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   91 | main(){
      | ^~~~