Submission #1015425

#TimeUsernameProblemLanguageResultExecution timeMemory
1015425phoenixNautilus (BOI19_nautilus)C++17
100 / 100
211 ms860 KiB
#include <bits/stdc++.h> using namespace std; struct bitMatrix { bitset<500> a[500]; int n, m; bitMatrix() {} bitMatrix(int n, int m) : n(n), m(m) {} bitMatrix(vector<vector<bool>> st) { n = (int)st.size(); m = (int)st[0].size(); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) a[i][j] = st[i][j]; } void move_up() { for (int i = 0; i < n - 1; i++) swap(a[i], a[i + 1]); a[n - 1].reset(); } void move_down() { for (int i = n - 1; i > 0; i--) swap(a[i - 1], a[i]); a[0].reset(); } void move_left() { for (int i = 0; i < n; i++) a[i] >>= 1; } void move_right() { for (int i = 0; i < n; i++) a[i] <<= 1; } void print() { for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) cout << a[i][j]; cout << '\n'; } cout << '\n'; } }; bitMatrix OR(const bitMatrix &a, const bitMatrix &b) { assert(a.n == b.n && a.m == b.m); bitMatrix res = a; for (int i = 0; i < res.n; i++) res.a[i] = res.a[i] | b.a[i]; return res; } bitMatrix AND(const bitMatrix &a, const bitMatrix &b) { assert(a.n == b.n && a.m == b.m); bitMatrix res = a; for (int i = 0; i < res.n; i++) res.a[i] = res.a[i] & b.a[i]; return res; } int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, L; cin >> n >> m >> L; bitMatrix a(n, m); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) { char c; cin >> c; a.a[i][j] = (c == '.'); } bitMatrix cur = a; for (int it = 0; it < L; it++) { char c; cin >> c; if (c == 'N') { cur.move_up(); cur = AND(cur, a); } if (c == 'S') { cur.move_down(); cur = AND(cur, a); } if (c == 'W') { cur.move_left(); cur = AND(cur, a); } if (c == 'E') { cur.move_right(); cur = AND(cur, a); } if (c == '?') { bitMatrix b(n, m), c; c = cur; c.move_up(); b = OR(b, c); c = cur; c.move_down(); b = OR(b, c); c = cur; c.move_left(); b = OR(b, c); c = cur; c.move_right(); b = OR(b, c); cur = AND(b, a); } } int ans = 0; for (int i = 0; i < n; i++) ans += cur.a[i].count(); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...