제출 #210628

#제출 시각아이디문제언어결과실행 시간메모리
210628casperwangNautilus (BOI19_nautilus)C++14
29 / 100
10 ms764 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 500;
int r, c, m;
int dx, dy;
int cnt;
string str;
string mp[MAXN+5];
int dp[MAXN+5][MAXN+5][2];

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> r >> c >> m;
  for (int i = 1; i <= r; i++) {
    cin >> mp[i];
    mp[i] = "#" + mp[i] + "#";
  }
  cin >> str;
  for (int i = 0; i <= c+1; i++) {
    mp[0] = mp[0] + "#";
    mp[r+1] = mp[r+1] + "#";
  }
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++)
      dp[i][j][1] = (mp[i][j] != '#');
  for (int k = 0; k < m; k++) {
    if (str[k] == 'S') dx = -1, dy = 0;
    if (str[k] == 'N') dx = 1, dy = 0;
    if (str[k] == 'E') dx = 0, dy = -1;
    if (str[k] == 'W') dx = 0, dy = 1;
    for (int i = 1; i <= r; i++)
      for (int j = 1; j <= c; j++)
        dp[i][j][k%2] = (mp[i][j] != '#') * (dp[i+dx][j+dy][(k+1)%2]);
    if (str[k] != '?') continue;
    for (int i = 1; i <= r; i++) {
      for (int j = 1; j <= c; j++) {
        dp[i][j][k%2] |= (mp[i][j] != '#') * (dp[i][j+1][(k+1)%2]);
        dp[i][j][k%2] |= (mp[i][j] != '#') * (dp[i][j-1][(k+1)%2]);
        dp[i][j][k%2] |= (mp[i][j] != '#') * (dp[i+1][j][(k+1)%2]);
        dp[i][j][k%2] |= (mp[i][j] != '#') * (dp[i-1][j][(k+1)%2]);
      }
    }
  }
  for (int i = 1; i <= r; i++)
    for (int j = 1; j <= c; j++)
      cnt += dp[i][j][(m+1)%2];
  cout << cnt << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...