Submission #1083090

#TimeUsernameProblemLanguageResultExecution timeMemory
1083090f0rizenNautilus (BOI19_nautilus)C++17
66 / 100
491 ms262144 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int inf = 1e9 + 7; const ll infll = 1e18; template<typename T> istream &operator>>(istream &is, vector<T> &a) { for (auto &i : a) { is >> i; } return is; } const array<int, 4> dx = {-1, 0, 1, 0}; const array<int, 4> dy = {0, 1, 0, -1}; int32_t main() { #ifdef LOCAL freopen("/tmp/input.txt", "r", stdin); #else ios::sync_with_stdio(false); cin.tie(nullptr); #endif int n, m, k; cin >> n >> m >> k; vector<string> a(n); cin >> a; string s; cin >> s; auto ok = [&](int i, int j) { return 0 <= i && i < n && 0 <= j && j < m; }; vector<vector<vector<bool>>> dp(k + 1, vector<vector<bool>>(n, vector<bool>(m))); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (a[i][j] != '#') { dp[0][i][j] = 1; } } } for (int t = 1; t <= k; ++t) { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (a[i][j] == '#') { continue; } if (s[t - 1] == 'N') { if (ok(i + 1, j)) { dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i + 1][j]); } } else if (s[t - 1] == 'E') { if (ok(i, j - 1)) { dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i][j - 1]); } } else if (s[t - 1] == 'S') { if (ok(i - 1, j)) { dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i - 1][j]); } } else if (s[t - 1] == 'W') { if (ok(i, j + 1)) { dp[t][i][j] = (dp[t][i][j] | dp[t - 1][i][j + 1]); } } else { for (int _ = 0; _ < 4; ++_) { int x = i + dx[_], y = j + dy[_]; if (ok(x, y)) { dp[t][i][j] = (dp[t][i][j] | dp[t - 1][x][y]); } } } } } } int ans = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { if (dp[k][i][j]) { ++ans; } } } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...