Language: C++

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
const int dx[] = {1,0,-1,0};
const int dy[] = {0,1,0,-1};
const int SIZE = 31;
const int INF = 1<<27;
int G[SIZE][SIZE], C[4];
int H, W;
struct dijkstra {
  int x, y, d, cost;
  State() {}
  State(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
  bool operator<(const State &s) const {
    return cost<s.cost;
  }
};
 
int dijkstra() {
  int cost[4][SIZE][SIZE];
  priority_queue<State,vector<State>,greater<State> > pq;
  pq.push(State(0,0,0,0));
  fill(cost[0][0], cost[4][0], INF);
  cost[0][0][0] = 0;
  while(!pq.empty()) {
    const State s = pq.top(); pq.pop();
    if(cost[s.d][s.y][s.x] < s.cost) continue;
    if(s.x == W-1 && s.y == H-1) return s.cost;
    for(int i=0; i<4; i++) {
      State t = s;
      t.cost += ( G[s.y][s.x] == i ? 0 : C[i] );
      t.d = (s.d + i) % 4;
      t.x += dx[t.d], t.y += dy[t.d];
      if(0 <= t.x && t.x < W 
     && 0 <= t.y && t.y < H 
     && cost[t.d][t.y][t.x] > t.cost) {
    pq.push(t);
    cost[t.d][t.y][t.x] = t.cost;
      }
    }
  }
   
  return INF;
}
 
int main() {
  while(cin >> W >> H, W+H) {
    for(int i=0; i<H; i++)
      for(int j=0; j<W; j++)
    cin >> G[i][j];
    for(int i=0; i<4; i++) cin >> C[i];
    cout << dijkstra() << endl;
  }
  return 0;
}

Compiler output:
a.cc:13:3: error: ISO C++ forbids declaration of 'State' with no type [-fpermissive]
   13 |   State() {}
      |   ^~~~~
a.cc:14:3: error: ISO C++ forbids declaration of 'State' with no type [-fpermissive]
   14 |   State(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
      |   ^~~~~
a.cc:15:24: error: 'State' does not name a type
   15 |   bool operator<(const State &s) const {
      |                        ^~~~~
a.cc: In member function 'int dijkstra::State()':
a.cc:13:12: warning: no return statement in function returning non-void [-Wreturn-type]
   13 |   State() {}
      |            ^
a.cc: In member function 'int dijkstra::State(int, int, int, int)':
a.cc:14:42: error: only constructors take member initializers
   14 |   State(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
      |                                          ^
a.cc:14:72: warning: no return statement in function returning non-void [-Wreturn-type]
   14 |   State(int x, int y, int d, int cost) : x(x), y(y), d(d), cost(cost) {}
      |                                                                        ^
a.cc: In member function 'bool dijkstra::operator<(const int&) const':
a.cc:16:19: error: request for member 'cost' in 's', which is of non-class type 'const int'
   16 |     return cost<s.cost;
      |                   ^~~~
a.cc: In function 'int dijkstra()':
a.cc:22:18: error: 'State' was not declared in this scope
   22 |   priority_queue<State,vector<State>,greater<State> > pq;
      |                  ^~~~~
a.cc:22:36: error: template argument 2 is invalid
   22 |   priority_queue<State,vector<State>,greater<State> > pq;
      |                                    ^
a.cc:22:53: error: template argument 1 is invalid
   22 |   priority_queue<State,vector<State>,greater<State> > pq;
      |                                                     ^
a.cc:22:53: error: template argument 2 is invalid
a.cc:22:53: error: template argument 3 is invalid
a.cc:23:6: error: request for member 'push' in 'pq', which is of non-class type 'int'
   23 |   pq.push(State(0,0,0,0));
      |      ^~~~
a.cc:26:13: error: request for member 'empty' in 'pq', which is of non-class type 'int'
   26 |   while(!pq.empty()) {
      |             ^~~~~
a.cc:27:11: error: 'State' does not name a type
   27 |     const State s = pq.top(); pq.pop();
      |           ^~~~~
a.cc:27:34: error: request for member 'pop' in 'pq', which is of non-class type 'int'
   27 |     const State s = pq.top(); pq.pop();
      |                                  ^~~
a.cc:28:13: error: 's' was not declared in this scope
   28 |     if(cost[s.d][s.y][s.x] < s.cost) continue;
      |             ^
a.cc:29:8: error: 's' was not declared in this scope
   29 |     if(s.x == W-1 && s.y == H-1) return s.cost;
      |        ^
a.cc:31:12: error: expected ';' before 't'
   31 |       State t = s;
      |            ^~
      |            ;
a.cc:32:7: error: 't' was not declared in this scope
   32 |       t.cost += ( G[s.y][s.x] == i ? 0 : C[i] );
      |       ^
a.cc:32:21: error: 's' was not declared in this scope
   32 |       t.cost += ( G[s.y][s.x] == i ? 0 : C[i] );
      |                     ^
a.cc:38:8: error: request for member 'push' in 'pq', which is of non-class type 'int'
   38 |     pq.push(t);
      |        ^~~~