#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define endl '\n'
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 1e5+1;
vector<vector<int>> rotation(200, vector<int>(2));
void solve(){
rotation['N'][0] = 1;
rotation['N'][1] = 2;
rotation['E'][0] = 0;
rotation['E'][1] = 1;
rotation['S'][0] = 3;
rotation['S'][1] = 0;
rotation['W'][0] = 2;
rotation['W'][1] = 3;
int n,m;
cin>>n>>m;
vector<vector<int>> dp(n, vector<int>(m,MOD));
vector<vector<char>> arr(n, vector<char>(m));
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin>>arr[i][j];
}
}
dp[0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(i + j == 0) continue;
if(j != 0 && arr[i][j-1] != 'X' && dp[i][j-1] != MOD){
dp[i][j] = min(dp[i][j], dp[i][j-1] + rotation[arr[i][j-1]][0]);
}
if(i != 0 && arr[i-1][j] != 'X' && dp[i-1][j] != MOD){
dp[i][j] = min(dp[i][j], dp[i-1][j] + rotation[arr[i-1][j]][1]);
}
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cout<<dp[i][j]<<" ";
}
cout<<endl;
}
cout<<(dp[n-1][m-1] == MOD ? -1: dp[n-1][m-1]);
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |