#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define endl '\n'
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
const int mod = 1e9 + 7;
const int N = 1e5 + 15;
const ll inf = 1e18;
vector<pii> node[N];
int dis[N];
bool vis[N];
int nm[301][301];
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int n,m;
cin >> n >> m;
int t = 1;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
nm[i][j] = t++;
}
}
vector<int> hall;
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++){
char x;
cin >> x;
int cur = nm[i][j];
if (x=='X') {
vis[cur] = 1;
continue;
}
int u = nm[i-1][j];
int r = nm[i][j+1];
int d = nm[i+1][j];
int l = nm[i][j-1];
if (x=='N'){
node[cur].pb({u,0});
node[cur].pb({r,1});
node[cur].pb({d,2});
node[cur].pb({l,3});
}
if (x=='E'){
node[cur].pb({r,0});
node[cur].pb({d,1});
node[cur].pb({l,2});
node[cur].pb({u,3});
}
if (x=='S'){
node[cur].pb({d,0});
node[cur].pb({l,1});
node[cur].pb({u,2});
node[cur].pb({r,3});
}
if (x=='W'){
node[cur].pb({l,0});
node[cur].pb({u,1});
node[cur].pb({r,2});
node[cur].pb({d,3});
}
}
}
memset(dis,0x3f,sizeof(dis));
priority_queue<pii> pq;
pq.push({0,nm[1][1]});
while (sz(pq)){
int u = pq.top().S;
int v = -pq.top().F;
pq.pop();
if (vis[u]) continue;
dis[u] = v;
vis[u] = 1;
for (auto [it,c] : node[u]){
if (v+c < dis[it]){
dis[it] = v+c;
pq.push({-dis[it],it});
}
}
}
cout << dis[nm[n][m]] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
3028 KB |
Output is correct |
2 |
Correct |
1 ms |
3028 KB |
Output is correct |
3 |
Incorrect |
2 ms |
3032 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3028 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |