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>
typedef long long int ll;
#define INF ll(1e9 + 7)
#define INF2 998244353
#define N (ll)(1e5 + 5)
using namespace std;
#define int ll
#define lsb(x) (x & (-x))
int r, c, m, g, h;
string s;
bitset<502> a[502], pos[502], t[502];
int d1[] = {0, 0, 1, -1}, d2[] = {1, - 1, 0, 0};
void solve(){
cin >> r >> c >> m;
for(int i=1; i<=r; i++){
cin >> s;
for(int j=1; j<=c; j++){
a[i][j] = s[j - 1] == '.';
pos[i][j] = a[i][j];
}
}
cin >> s;
for(int i=0; i<m; i++){
if(s[i] == '?'){
for(int n=1; n<=r; n++){
for(int l=1; l<=c; l++){
if(pos[n][l]){
for(int j=0; j<4; j++){
t[n][l] = a[n + d1[j]][l + d2[j]];
if(t[n][l])break;
}
}
}
}
for(int i=1; i<=r; i++){
a[i] = t[i];
t[i] &= 0;
}
}
else if(s[i] == 'W'){
for(int n=1; n<=r; n++){
for(int l=1; l<=c; l++){
if(pos[n][l]){
a[n][l] = a[n][l + 1];
}
}
}
}
else if(s[i] == 'E'){
for(int n=1; n<=r; n++){
for(int l=c; l; l--){
if(pos[n][l]){
a[n][l] = a[n][l - 1];
}
}
}
}
else if(s[i] == 'S'){
for(int n=r; n; n--){
for(int l=1; l<=c; l++){
if(pos[n][l]){
a[n][l] = a[n - 1][l];
}
}
}
}
else{
for(int n=1; n<=r; n++){
for(int l=1; l<=c; l++){
if(pos[n][l]){
a[n][l] = a[n + 1][l];
}
}
}
}
}
int sum = 0;
for(int n=r; n; n--){
for(int l=1; l<=c; l++){
sum += a[n][l];
}
}
cout << sum;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int T = 1;
//cin>>T;
while (T--){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |