Submission #163348

#TimeUsernameProblemLanguageResultExecution timeMemory
163348SaboonNautilus (BOI19_nautilus)C++14
100 / 100
205 ms772 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const int maxn = 500; const int inf = 1e9; bitset<maxn> dp[2][maxn], sea[maxn]; int main(){ ios_base::sync_with_stdio(false); int n, m, k; cin >> n >> m >> k; for (int i = 0; i < n; i++){ string s; cin >> s; for (int j = 0; j < m; j++){ if (s[j] == '.') sea[i][j] = 1; else sea[i][j] = 0; } } string s; cin >> s; for (int i = 0; i < n; i++) dp[0][i] = sea[i]; for (int x = 1; x <= k; x++){ int p = (x & 1); for (int i = 0; i < n; i++) dp[p][i].reset(); if (s[x - 1] == 'N' or s[x - 1] == '?'){ for (int i = 0; i < n - 1; i++) dp[p][i] |= (dp[1 - p][i + 1] & sea[i]); } if (s[x - 1] == 'S' or s[x - 1] == '?'){ for (int i = 1; i < n; i++) dp[p][i] |= (dp[1 - p][i - 1] & sea[i]); } if (s[x - 1] == 'E' or s[x - 1] == '?'){ for (int i = 0; i < n; i++) dp[p][i] |= ((dp[1 - p][i] << 1) & sea[i]); } if (s[x - 1] == 'W' or s[x - 1] == '?'){ for (int i = 0; i < n; i++) dp[p][i] |= ((dp[1 - p][i] >> 1) & sea[i]); } } int p = (k & 1); int cnt = 0; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) if (dp[p][i][j]) cnt ++; cout << cnt << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...