Submission #1083065

#TimeUsernameProblemLanguageResultExecution timeMemory
1083065f0rizenNautilus (BOI19_nautilus)C++17
66 / 100
465 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};
const string dd = "SWNE";

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 good = [&](int i, int j) {
        return 0 <= i && i < n && 0 <= j && j < m && a[i][j] != '#';
    };
    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;
                }
                bool ok = false;
                for (int _ = 0; _ < 4; ++_) {
                    int x = i + dx[_], y = j + dy[_];
                    if (good(x, y)) {
                        if ((s[t - 1] == dd[_] || s[t - 1] == '?') && dp[t - 1][x][y]) {
                            ok = true;
                            break;
                        }
                    }
                }
                if (ok) {
                    dp[t][i][j] = 1;
                }
            }
        }
    }
    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...