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>
using namespace std;
const int N = 501;
int main() {
int n, m, k;
cin >> n >> m >> k;
bitset<N> dp[2][1 + N];
bitset<N> grid[1 + N];
for(int i = 1; i <= n; i++){
for(int j = 0; j < m; j++){
char c;
cin >> c;
if(c == '.'){
grid[i].set(j, 1);
dp[0][i].set(j, 1);
}
else{
grid[i].set(j, 0);
dp[0][i].set(j, 0);
}
}
}
string s;
cin >> s;
for(int i = 1; i <= k; i++){
for(int j = 1; j <= n; j++){
if(s[i - 1] == 'W'){
dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] >> 1);
}
else if(s[i - 1] == 'E'){
dp[i % 2][j] = grid[j] & (dp[1 - i % 2][j] << 1);
}
else if(s[i - 1] == 'N'){
dp[i % 2][j] = grid[j] & dp[1 - i % 2][j + 1];
}
else if(s[i - 1] == 'S'){
dp[i % 2][j] = grid[j] & dp[1 - i % 2][j - 1];
}
else{
dp[i % 2][j] = grid[j] & ((dp[1 - i % 2][j] >> 1) | (dp[1 - i % 2][j] << 1) | (dp[1 - i % 2][j + 1]) | (dp[1 - i % 2][j - 1]));
}
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
ans += dp[k % 2][i].count();
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |