Submission #515641

#TimeUsernameProblemLanguageResultExecution timeMemory
515641nhphucqtNautilus (BOI19_nautilus)C++17
100 / 100
181 ms396 KiB
#include <bits/stdc++.h> using namespace std; const int D[4][2] = {{0,-1},{0,1},{-1,0},{1,0}}; const int NROW = 507; const int NCOL = 507; const int N = 5007; int numRow, numCol, n; bitset<NCOL> ans[NROW], tmp[NROW], islands[NROW]; int res; void process(char c) { if (c == 'W') { for (int i = 1; i <= numRow; ++i) { ans[i] >>= 1; ans[i] &= islands[i]; } } else if (c == 'E') { for (int i = 1; i <= numRow; ++i) { ans[i] <<= 1; ans[i] &= islands[i]; } } else if (c == 'N') { for (int i = 1; i <= numRow; ++i) { ans[i] = ans[i+1] & islands[i]; } } else if (c == 'S') { for (int i = numRow; i >= 1; --i) { ans[i] = ans[i-1] & islands[i]; } } else { for (int i = 1; i <= numRow; ++i) { tmp[i] = ((ans[i]>>1) | (ans[i]<<1) | ans[i-1] | ans[i+1]) & islands[i]; } for (int i = 1; i <= numRow; ++i) { ans[i] = tmp[i]; } } // for (int i = 1; i <= numRow; ++i, cerr << '\n') // for (int j = 1; j <= numCol; ++j) cerr << ans[i][j]; // cerr << '\n'; } int main() { cin.tie(nullptr)->sync_with_stdio(false); // freopen("NAUTILUS.inp", "r", stdin); // freopen("NAUTILUS.out", "w", stdout); cin >> numRow >> numCol >> n; for (int i = 1; i <= numRow; ++i) for (int j = 1; j <= numCol; ++j) { char c; cin >> c; islands[i][j] = c == '.'; ans[i][j] = c == '.'; } // for (int i = 1; i <= numRow; ++i, cerr << '\n') // for (int j = 1; j <= numCol; ++j) cerr << ans[i][j]; // cerr << '\n'; for (int i = 1; i <= n; ++i) { char c; cin >> c; process(c); } for (int i = 1; i <= numRow; ++i) for (int j = 1; j <= numCol; ++j) { res += ans[i][j]; } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...