Submission #802022

#TimeUsernameProblemLanguageResultExecution timeMemory
802022Soumya1Nautilus (BOI19_nautilus)C++17
100 / 100
139 ms668 KiB
#include <bits/stdc++.h>
#ifdef __LOCAL__
  #include <debug_local.h>
#endif
using namespace std;
using bs = bitset<501>;
void testCase() {
  int r, c, m;
  cin >> r >> c >> m;
  vector<bs> ok(r);
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) {
      char c;
      cin >> c;
      if (c == '.') ok[i][j] = 1;
    }
  }
  string s;
  cin >> s;
  vector<bs> dp = ok, ndp(r);
  for (int i = 0; i < m; i++) {
    for (int i = 0; i < r; i++) ndp[i].reset();
    if (s[i] == 'E' || s[i] == '?') {
      for (int i = 0; i < r; i++) {
        ndp[i] |= dp[i] << 1;
      }
    }
    if (s[i] == 'W' || s[i] == '?') {
      for (int i = 0; i < r; i++) {
        ndp[i] |= dp[i] >> 1;
      }
    }
    if (s[i] == 'N' || s[i] == '?') {
      for (int i = 0; i < r - 1; i++) {
        ndp[i] |= dp[i + 1];
      }
    }
    if (s[i] == 'S' || s[i] == '?') {
      for (int i = 1; i < r; i++) {
        ndp[i] |= dp[i - 1];
      }
    }
    for (int i = 0; i < r; i++) {
      ndp[i] &= ok[i];
    }
    swap(dp, ndp);
  }
  int ans = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < c; j++) ans += dp[i][j];
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  testCase();
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...