This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
char str[505][505], qry[5005];
std::bitset<505> dp[505][2], arr[505];
int main() {
int r, c, m, ans = 0; assert(3==scanf("%d %d %d", &r, &c, &m));
for (int i = 1; i <= r && 1==scanf("%s", str[i]+1); i++) for (int j = 1; j <= c; j++) if (str[i][j] == '.') dp[i][0][j] = arr[i][j] = 1;
assert(1==scanf("%s", qry+1));
for (int i = 1; i <= m; i++) for (int j = 1; j <= r; j++)
if (qry[i] != '?') dp[j][(i&1)]=(qry[i]=='N'||qry[i]=='S') ? (dp[j+1*(qry[i]=='N'?1:-1)][(i&1)^1] & arr[j]) : ((qry[i]=='E') ? ((dp[j][(i&1)^1]<<1) & arr[j]) : ((dp[j][(i&1)^1]>>1) & arr[j]));
else dp[j][(i&1)] = (dp[j+1][(i&1)^1] | dp[j-1][(i&1)^1] | (dp[j][(i&1)^1] >> 1) | (dp[j][(i&1)^1] << 1)) & arr[j];
for (int i = 1; i <= r; i++) ans += dp[i][m&1].count();
return !printf("%d\n", ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |