//#pragma GCC target ("avx2")
//#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define pb push_back
const int N = 1e3+100, NN=26;
const int mod=1e9+7;
//int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); }
//int lcm(int a, int b) { return a / gcd(a, b) * b; }
//int binpow(int a,int b){if(!b)return 1; if(b&1)return a*binpow(a,b-1)%mod; int x=binpow(a,b/2); return x*x%mod;}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int r, c, m;
cin >> r >> c >> m;
char a[r+1][c+1];
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++) cin >> a[i][j];
}
string s;
cin >> s;
int ans=0;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
int ii=i, jj=j, h=0;
bool b=0;
while(h<m){
if(s[h]=='N'){
if(ii-1>r || a[ii-1][jj]=='#'){b=1; break;}
ii--;
}
else if(s[h]=='S'){
if(ii+1<1 || a[ii+1][jj]=='#'){b=1; break;}
ii++;
}
else if(s[h]=='E'){
if(jj+1>c || a[ii][jj+1]=='#'){b=1; break;}
jj++;
}
else{
if(jj-1<1 || a[ii][jj-1]=='#'){b=1; break;}
jj--;
}
h++;
}
if(b==0) ans++;
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |