//gm --- akezhon
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
#define double long double
// #define int long long
using namespace std;
const int N=1e5+7;
const int mod=998244353;
const int inf=2e18;
set <pii> st[5005];
void AlemAmenov(){
int n, m, k;
string s;
cin >> n >> m >> k;
string a[n+1];
for(int i=0; i < n; i++){
cin >> a[i];
}
cin >> s;
s=' '+s;
queue<pair<pii, int>>q;
for(int i=0; i < n; i++){
for(int j=0; j < m; j++){
if(a[i][j] == '.')st[1].insert({i, j});
}
}
for(int it=1; it < s.size(); it++){
for(auto [i, j] : st[it]){
if(s[it] == 'N' || s[it] == '?'){
if(i && a[i-1][j] == '.')st[it+1].insert({i-1, j});
}
if(s[it] == 'S' || s[it] == '?'){
if(i<n-1 && a[i+1][j] == '.')st[it+1].insert({i+1, j});
}
if(s[it] == 'W' || s[it] == '?'){
if(j && a[i][j-1] == '.')st[it+1].insert({i, j-1});
}
if(s[it] == 'E' || s[it] == '?'){
if(j<m-1 && a[i][j+1] == '.')st[it+1].insert({i, j+1});
}
}
}
cout << st[s.size()].size() << '\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int RealName=1;
// cin >> RealName;
// freopen("connect.in", "r", stdin);
// freopen("connect.out", "w", stdout);
while(RealName--)
AlemAmenov();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
nautilus.cpp:22:15: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
22 | const int inf=2e18;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |