Submission #865819

#TimeUsernameProblemLanguageResultExecution timeMemory
865819Charizard2021Nautilus (BOI19_nautilus)C++17
100 / 100
146 ms1008 KiB
#include<bits/stdc++.h> using namespace std; const int N = 501; int main() { int n, m, k; cin >> n >> m >> k; bitset<N> dp[2][1 + N]; bitset<N> grid[1 + N]; for(int i = 1; i <= n; i++){ for(int j = 0; j < m; j++){ char c; cin >> c; if(c == '.'){ grid[i].set(j, 1); dp[0][i].set(j, 1); } else{ grid[i].set(j, 0); dp[0][i].set(j, 0); } } } string s; cin >> s; for(int i = 1; i <= k; i++){ for(int j = 1; j <= n; j++){ if(s[i - 1] == 'W'){ dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] >> 1); } else if(s[i - 1] == 'E'){ dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] << 1); } else if(s[i - 1] == 'N'){ dp[i % 2][j] = grid[j] & dp[1 - i % 2][j + 1]; } else if(s[i - 1] == 'S'){ dp[i % 2][j] = grid[j] & dp[1 - i % 2][j - 1]; } else{ dp[i % 2][j] = grid[j] & ((dp[1 - i % 2][j] >> 1) | (dp[1 - i % 2][j] << 1) | (dp[1 - i % 2][j + 1]) | (dp[1 - i % 2][j - 1])); } } } int ans = 0; for(int i = 1; i <= n; i++){ ans += dp[k % 2][i].count(); } cout << ans << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...