Submission #1137346

#TimeUsernameProblemLanguageResultExecution timeMemory
1137346lopkusNautilus (BOI19_nautilus)C++20
100 / 100
120 ms536 KiB
#include <bits/stdc++.h> #define inf 1e18 using namespace std; const int nmax = 500; bitset <nmax> bitmask[nmax + 1], dp[2][nmax + 1]; void solve(int a, char b, int n, int m) { int i; for(i = 1; i <= n; i++) dp[a&1][i].reset(); if(b == 'S' || b == '?') { for(i = 1; i < n; i++) dp[a&1][i + 1] |= dp[1 - (a&1)][i]; } if(b == 'E' || b == '?') { for(i = 1; i <= n; i++) { dp[a&1][i] |= dp[1 - (a&1)][i]<<1; } } if(b == 'N' || b == '?') { for(i = 2; i <= n; i++) dp[a&1][i - 1] |= dp[1 - (a&1)][i]; } if(b == 'W' || b == '?') { for(i = 1; i <= n; i++) dp[a&1][i] |= dp[1 - (a&1)][i]>>1; } for(i = 1; i <= n; i++) dp[a&1][i] &= bitmask[i]; } int main() { ios :: sync_with_stdio(false); cin.tie(0); int n, m, q, i, j, rez = 0; char ch; cin >> n >> m >> q; for(i = 1; i <= n; i++) { for(j = 0; j < m; j++) { cin >> ch; if(ch == '#') bitmask[i][j] = 0; else bitmask[i][j] = 1; dp[0][i][j] = bitmask[i][j]; } } for(i = 1; i <= q; i++) { cin >> ch; solve(i, ch, n, m); } for(i = 1; i <= n; i++) { rez += dp[q&1][i].count(); } cout << rez; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...