제출 #687507

#제출 시각아이디문제언어결과실행 시간메모리
687507stanislavpolynNautilus (BOI19_nautilus)C++17
100 / 100
191 ms924 KiB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? a = b, 1 : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 505;

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, 1, -1};
const string d = "SNEW";

int n, m, k;
char a[N][N];
string s;

bool dp[N][N], ndp[N][N];

bool valid(int x, int y) {
    return x >= 1 && y >= 1 && x <= n && y <= m && a[x][y] != '#';
}

bitset<505> b[N], nb[N];

int brute() {
    fr (i, 1, n) {
        fr (j, 1, m) {
            if (a[i][j] != '#') {
                dp[i][j] = 1;
            }
        }
    }


    fr (step, 0, sz(s) - 1) {
        int p = find(all(d), s[step]) - d.begin();

        fr (i, 1, n) {
            fr (j, 1, m) {
                if (dp[i][j]) {
                    if (p != sz(d)) {
                        if (valid(i + dx[p], j + dy[p])) {
                            ndp[i + dx[p]][j + dy[p]] = 1;
                        }
                    } else {
                        fr (cur, 0, 3) {
                            if (valid(i + dx[cur], j + dy[cur])) {
                                ndp[i + dx[cur]][j + dy[cur]] = 1;
                            }
                        }
                    }
                }
            }
        }
        fr (i, 1, n) {
            fr (j, 1, m) {
                dp[i][j] = ndp[i][j];
                ndp[i][j] = 0;
            }
        }
    }

    int ans = 0;
    fr (i, 1, n) {
        fr (j, 1, m) {
            if (dp[i][j]) {
                ans++;
            }
        }
    }
    return ans;
}

bitset<505> good[N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m >> k;

    fr (i, 1, n) {
        fr (j, 1, m) {
            cin >> a[i][j];
            if (a[i][j] == '.') {
                good[i][j] = 1;
            }
        }
    }

    cin >> s;

    fr (i, 1, n) {
        fr (j, 1, m) {
            if (a[i][j] == '.') {
                b[i][j] = 1;
            }
        }
    }

    fr (step, 0, sz(s) - 1) {
        if (s[step] == 'W') {
            fr (i, 1, n) {
                nb[i] = b[i] >> 1;
            }
        }
        if (s[step] == 'E') {
            fr (i, 1, n) {
                nb[i] = b[i] << 1;
            }
        }
        if (s[step] == 'N') {
            fr (i, 1, n - 1) {
                nb[i] = b[i + 1];
            }
        }
        if (s[step] == 'S') {
            rf (i, n, 2) {
                nb[i] = b[i - 1];
            }
        }
        if (s[step] == '?') {
            fr (i, 1, n) {
                nb[i] |= b[i] >> 1;
            }
            fr (i, 1, n) {
                nb[i] |= b[i] << 1;
            }
            fr (i, 1, n - 1) {
                nb[i] |= b[i + 1];
            }
            rf (i, n, 2) {
                nb[i] |= b[i - 1];
            }
        }

        fr (i, 1, n) {
            b[i] = nb[i] & good[i];
            nb[i].reset();
        }
    }

    int ans = 0;
    fr (i, 1, n) {
        ans += b[i].count();
    }
    cout << ans << "\n";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...