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 ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ff first
#define ss second
using namespace std;
const int N=2*1e5+7;
string a[N];
int main()
{
int n, m, q;
cin >> n >> m >> q;
for (int i=1;i<=n;i++) cin >> a[i];
string s;
cin >> s;
int mx=0, mn=1e9, mx1=0, mn1=1e9, res=0, res1=0;
for (int i=0;i<q;i++){
if (s[i] == 'E') res++;
if (s[i] == 'W') res--;
if (s[i] == 'N') res1++;
if (s[i] == 'S') res1--;
mn=min(mn, res);
mx=max(mx, res);
mn1=min(mn1, res1);
mx1=max(mx1, res1);
}
res=res1=0;
ll ans=0;
for (int i=1;i<=n;i++){
for (int j=0;j<m;j++){
if (a[i][j] == '.'){
res=res1=0;
for (int j1=i-1;j1>0;j1--){
if (a[j1][j] == '.') res++;
else {
res=0;
break;
}
}
if (res+mn1 >= 0){
res=0;
for (int j1=i+1;j1<=n;j1++){
if (a[j1][j] == '.') res++;
else {
res=0;
break;
}
}
if (res >= mx1){
res=0;
for (int j1=j-1;j1>=0;j1--){
if (a[i][j1] == '.') res++;
else {
res=0;
break;
}
}
if (res+mn >= 0){
res=0;
for (int j1=i+1;j1<m;j1++){
if (a[i][j1] == '.') res++;
else {
res=0;
break;
}
}
if (res >= mx) 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... |