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>
#define ll long long
#define F first
#define S second
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<bitset<500>> row(n);
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
char c;
cin >> c;
if(c == '.'){
row[i][j] = 1;
}
}
}
string s;
cin >> s;
vector<vector<bitset<500>>> dp(k+1, vector<bitset<500>> (n));
for(int i = 0; i < n; i++){
dp[0][i] = row[i];
}
for(int x = 1; x <= k; x++){
for(int i = 0; i < n; i++){
if(s[x-1] == 'E'){
dp[x][i] = (dp[x-1][i]<<1)&row[i];
}
else if(s[x-1] == 'W'){
dp[x][i] = (dp[x-1][i]>>1)&row[i];
}
else if(s[x-1] == 'N' && i+1 < n){
dp[x][i] = dp[x-1][i+1]&row[i];
}
else if(s[x-1] == 'S' && i-1 >= 0){
dp[x][i] = dp[x-1][i-1]&row[i];
}
else if(s[x-1] == '?'){
dp[x][i] |= (dp[x-1][i]<<1);
dp[x][i] |= (dp[x-1][i]>>1);
if(i+1 < n){
dp[x][i] |= dp[x-1][i+1];
}
if(i-1 >= 0){
dp[x][i] |= dp[x-1][i-1];
}
dp[x][i] &= row[i];
}
}
}
int ans = 0;
for(int i = 0; i < n; i++){
ans += dp[k][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... |