#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
template<class T> bool remin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool remax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 102;
vector<array<int, 2>> dir = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
int dp[N][N][N], is[N][N];
int n, m, k;
char a[N][N];
string s;
bool f(int i, int j, int x) {
if(i < 1 || i > n || j < 1 || j > m || x > k) return 0;
if(dp[i][j][x] != -1) return dp[i][j][x];
if(a[i][j] == '#') return dp[i][j][x] = 0;
if(x == k) {
return dp[i][j][x] = is[i][j] = true;
}
if(s[x] == 'N') return dp[i][j][x] = f(i + 1, j, x + 1);
else if(s[x] == 'S') return dp[i][j][x] = f(i - 1, j, x + 1);
else if(s[x] == 'E') return dp[i][j][x] = f(i, j + 1, x + 1);
else if(s[x] == 'W') return dp[i][j][x] = f(i, j - 1, x + 1);
else {
for(array<int, 2> dx : dir) {
dp[i][j][x] |= f(i + dx[0], j + dx[1], x + 1);
}
}
return dp[i][j][x];
}
signed main() {
std::ios::sync_with_stdio(0);
std::cout.tie(0);
std::cin.tie(0);
int i, j;
cin >> n >> m >> k;
for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) cin >> a[i][j];
cin >> s;
memset(dp, -1, sizeof dp);
for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) f(i, j, 0);
int ans = 1;
for(i = 1; i <= n; i++) for(j = 1; j <= m; j++) ans += is[i][j];
//for(i = 1; i <= n; i++) { for(j = 1; j <= m; j++) cout << is[i][j] << " "; cout << "\n"; }
cout << ans << "\n";
return 0;
}
Compilation message
nautilus.cpp: In function 'bool f(int, int, int)':
nautilus.cpp:26:43: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
26 | if(a[i][j] == '#') return dp[i][j][x] = 0;
| ~~~~~~~~~~~~^~~
nautilus.cpp:28:28: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
28 | return dp[i][j][x] = is[i][j] = true;
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
nautilus.cpp:30:40: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
30 | if(s[x] == 'N') return dp[i][j][x] = f(i + 1, j, x + 1);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
nautilus.cpp:31:45: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
31 | else if(s[x] == 'S') return dp[i][j][x] = f(i - 1, j, x + 1);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
nautilus.cpp:32:45: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
32 | else if(s[x] == 'E') return dp[i][j][x] = f(i, j + 1, x + 1);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
nautilus.cpp:33:45: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
33 | else if(s[x] == 'W') return dp[i][j][x] = f(i, j - 1, x + 1);
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
4608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
4608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
19 ms |
4608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |