이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN=500;
int n, m, q;
bitset<mxN> mask[mxN], dp[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> q;
for (int i=0; i<n; ++i) {
string s;
cin >> s;
for (int j=0; j<m; ++j)
if (s[j]=='.')
mask[i][j]=1, dp[i][j]=1;
}
string query;
cin >> query;
for (char c : query) {
bitset<mxN> ndp[mxN];
if (c=='W'||c=='?')
for (int i=0; i<n; ++i)
ndp[i]|=(dp[i]>>1)&mask[i];
if (c=='E'||c=='?')
for (int i=0; i<n; ++i)
ndp[i]|=(dp[i]<<1)&mask[i];
if (c=='N'||c=='?')
for (int i=1; i<n; ++i)
ndp[i-1]|=dp[i]&mask[i-1];
if (c=='S'||c=='?')
for (int i=0; i+1<n; ++i)
ndp[i+1]|=dp[i]&mask[i+1];
for (int i=0; i<n; ++i)
swap(dp[i], ndp[i]);
}
int ans=0;
for (int i=0; i<n; ++i)
ans+=dp[i].count();
cout << ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |