Submission #1187592

#TimeUsernameProblemLanguageResultExecution timeMemory
1187592omerkingNautilus (BOI19_nautilus)C++20
100 / 100
209 ms832 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define endl "\n" using namespace std; using namespace __gnu_pbds; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template <typename T, typename key = less<T>> using ordered_set = tree<T, null_type, key, rb_tree_tag, tree_order_statistics_node_update>; const ll N = 505; string s[N]; bitset<N> bs[N], nbs[N], good[N]; ll n, m, k; void solve() { cin >> n >> m >> k; for (ll i = 1; i <= n; i++) { cin >> s[i]; s[i] = "#" + s[i]; } string dir; cin >> dir; dir = ' ' + dir; for (ll i = 1; i <= n; i++) for (ll j = 1; j <= m; j++) bs[i][j] = good[i][j] = s[i][j] != '#'; for (ll x = 1; x <= k; x++) { for (ll i = 1; i <= n; i++) nbs[i] = 0; if (dir[x] == 'N') { for (ll i = 1; i < n; i++) nbs[i] = bs[i + 1] & good[i]; } else if (dir[x] == 'S') { for (ll i = 2; i <= n; i++) nbs[i] = bs[i - 1] & good[i]; } else if (dir[x] == 'E') { for (ll i = 1; i <= n; i++) nbs[i] = (bs[i] << 1) & good[i]; } else if (dir[x] == 'W') { for (ll i = 1; i <= n; i++) nbs[i] = (bs[i] >> 1) & good[i]; } else { for (ll i = 1; i <= n; i++) nbs[i] = (bs[i - 1] | bs[i + 1] | (bs[i] << 1) | (bs[i] >> 1)) & good[i]; } for (ll i = 1; i <= n; i++) bs[i] = nbs[i]; } ll ans = 0; for (ll i = 1; i <= n; i++) ans += bs[i].count(); cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); ll t = 1; for (ll cs = 1; cs <= t; cs++) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...