# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
496362 | Ziel | Nautilus (BOI19_nautilus) | C++17 | 6 ms | 3584 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* LES GREATEABLES BRO TEAM
**/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define sz(x) (int)x.size()
const bool FLAG = false;
void setIO(const string &f = "");
#define int ll
bool dp[110][110][112];
void solve() {
int r, c, m;
cin >> r >> c >> m;
vector<vector<char>> a(r + 1, vector<char>(c + 1));
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
cin >> a[i][j];
}
}
string s;
cin >> s;
auto in_frame = [r, c](int x, int y) -> bool {
return x >= 1 && x <= r && y >= 1 && y <= c;
};
for (int k = 0; k <= m; k++) {
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
if (k == 0) {
if (a[i][j] == '.')
dp[i][j][k] = true;
} else {
if (a[i][j] == '#') {
dp[i][j][k] = false;
continue;
}
if (s[k - 1] == '?') {
if (in_frame(i - 1, j))
dp[i][j][k] |= dp[i - 1][j][k - 1];
if (in_frame(i + 1, j))
dp[i][j][k] |= dp[i + 1][j][k - 1];
if (in_frame(i, j - 1))
dp[i][j][k] |= dp[i][j - 1][k - 1];
if (in_frame(i, j + 1))
dp[i][j][k] |= dp[i][j + 1][k - 1];
} else if (s[k - 1] == 'N' && in_frame(i + 1, j)) {
dp[i][j][k] |= dp[i + 1][j][k - 1];
} else if (s[k - 1] == 'S' && in_frame(i - 1, j)) {
dp[i][j][k] |= dp[i - 1][j][k - 1];
} else if (s[k - 1] == 'E' && in_frame(i, j - 1)) {
dp[i][j][k] |= dp[i][j - 1][k - 1];
} else if (s[k - 1] == 'W' && in_frame(i, j + 1)) {
dp[i][j][k] |= dp[i][j + 1][k - 1];
}
}
}
}
}
int ans = 0;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= c; j++) {
ans += dp[i][j][m];
}
}
cout << ans;
}
signed main() {
setIO();
int tt = 1;
if (FLAG) {
cin >> tt;
}
while (tt--) {
solve();
}
return 0;
}
void setIO(const string &f) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen((f + ".in").c_str(), "r")) {
freopen((f + ".in").c_str(), "r", stdin);
freopen((f + ".out").c_str(), "w", stdout);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |