#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
int r,c,n,ans;
string s;
char a[106][106];
bool used[106][106];
void rec(int ind, int x, int y){
if(x <= 0 || x > r) return;
if(y <= 0 || y > c) return;
if(a[x][y] != '.') return;
if(ind == n + 1){
used[x][y] = 1;
return;
}
if(s[ind] == 'N'){
rec(ind + 1, x - 1, y);
}
else if(s[ind] == 'E'){
rec(ind + 1, x, y + 1);
}
else if(s[ind] == 'S'){
rec(ind + 1, x + 1, y);
}
else if(s[ind] == 'W'){
rec(ind + 1, x, y - 1);
}
else {
rec(ind + 1, x + 1, y);
rec(ind + 1, x - 1, y);
rec(ind + 1, x, y - 1);
rec(ind + 1, x, y + 1);
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> r >> c >> n;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
cin >> a[i][j];
}
}
cin >> s;
s = " " + s;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
if(a[i][j] == '.'){
rec(1,i,j);
}
}
}
for(int i = 1; i <= r; i++){
for(int j = 1; j <= c; j++){
if(used[i][j]) ans++;
}
}
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... |