#include <iostream>
#include <vector>
#include <map>
using namespace std;
int n, m, len;
string s;
bool check(int i, int j) {
if(i > -1 && j > -1 && i < n && j < m) return true;
return false;
}
int main() {
cin >> n >> m >> len;
vector<string> a(n);
for(int i = 0; i < n; i++) cin >> a[i];
cin >> s;
//dp
vector<vector<vector<bool>>> dp(len+1, vector<vector<bool>>(n, vector<bool>(m)));
//base case
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) dp[0][i][j] = (a[i][j] == '.');
}
//transition
vector<pair<int,int>> dirs = {
{-1, 0},
{0, 1},
{1, 0},
{0, -1}
};
map<char,int> mp = {
{'N', 0},
{'E', 1},
{'S', 2},
{'W', 3}
};
pair<int,int> dir;
for(int k = 1; k <= len; k++) {
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) {
if(a[i][j] == '#') {
cout << "# ";
continue;
}
if(s[k-1] == '?') {
for(auto dir : dirs) {
if(check(i+dir.first, j+dir.second) && dp[k-1][i+dir.first][j+dir.second]) dp[k][i][j] = 1;
}
}
else {
dir = dirs[(mp[s[k-1]]+2)%4];
if(check(i+dir.first, j+dir.second) && dp[k-1][i+dir.first][j+dir.second]) dp[k][i][j] = 1;
}
//cout << dp[k][i][j] << " ";
}
//cout << "\n";
}
//cout << "\n";
}
//final state
int res = 0;
for(int i = 0; i < n; i++) {
for(int j = 0; j < m; j++) res += dp[len][i][j];
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
1112 KB |
Output is correct |
2 |
Incorrect |
13 ms |
1400 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |