#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define v(a) vector<a>
#define p(a, b) pair<a, b>
#define F first
#define S second
ll n, m;
map<p(ll, ll), bool> vis;
map<char, ll> base;
v(v(char)) arr;
bool pos(ll x, ll y){
if(x < 0 || y < 0 || x >= n || y >= m) return false;
if(vis[{x, y}]) return false;
if(arr[x][y] == 'X' && x != n-1 && y != m-1) return false;
return true;
}
ll cost(ll a, ll b){
return ((b-a)+4)%4;
}
int main(){
cin >> n >> m;
arr.resize(n+5);
for(int i = 0; i < n; i++)arr[i].resize(m+5);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++) cin >> arr[i][j];
}
bool ok = false;
queue<p(ll, ll)> temp;
temp.push({0, 0});
while(!temp.empty()){
ll x = temp.front().F, y = temp.front().S;
temp.pop();
vis[{x, y}] = true;
if(x == n-1 && y == m-1){
ok = true;
break;
}
if(arr[x][y] == 'X') continue;
if(pos(x+1, y))temp.push({x+1, y});
if(pos(x, y+1)) temp.push({x, y+1});
if(pos(x-1, y)) temp.push({x-1, y});
if(pos(x, y-1)) temp.push({x, y-1});
}
if(!ok) cout << -1;
else {
vis.clear();
priority_queue<p(ll, p(ll, ll)), v(p(ll, p(ll, ll))), greater<p(ll, p(ll, ll))> > pq;
pq.push({0, {0, 0}});
base['N'] = 1;
base['E'] = 2;
base['S'] = 3;
base['W'] = 4;
ll ans = 1e9;
while(!pq.empty()){
ll cur = pq.top().F, x = pq.top().S.F, y = pq.top().S.S;
// cout << cur << " " << x << " " << y << endl;
pq.pop();
if(vis[{x, y}]) continue;
vis[{x, y}] = true;
if(x == n-1 && y == m-1){
ans = cur;
break;
}
if(arr[x][y] == 'X') continue;
if(pos(x+1, y)){pq.push({cur + cost(base[arr[x][y]], 3), {x+1, y}});
if(pos(x-1, y)) pq.push({cur + cost(base[arr[x][y]], 1), {x-1, y}});
if(pos(x, y+1)) pq.push({cur + cost(base[arr[x][y]], 2), {x, y+1}});
if(pos(x, y-1)) pq.push({cur + cost(base[arr[x][y]], 4), {x, y-1}});
}
cout << ans;
}
}
Compilation message
adventure.cpp: In function 'int main()':
adventure.cpp:81:1: error: expected '}' at end of input
81 | }
| ^
adventure.cpp:23:11: note: to match this '{'
23 | int main(){
| ^