This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
int trans(char ch) {
switch(ch) {
case 'N':
return 0;
case 'E':
return 1;
case 'S':
return 2;
case 'W':
return 3;
default:
return -1;
}
}
int dis(int from, int to) {
if(from <= to) return to-from;
else return 4-from+to;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m, res = 0;
bool ok = true;
cin >> n >> m;
string temp;
vector<vector<int>> map(n, vector<int>(m));
for(int i = 0; i < n; i++) {
cin >> temp;
for(int j = 0; j < m; j++) {
if(i == n-1 && j == m-1) continue;
if(temp[j] == 'X') ok = false;
map[i][j] = trans(temp[j]);
res+=dis(map[i][j], 1);
}
}
if(ok) cout << res << "\n";
else cout << "-1\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |