This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define no1 cout<<"-1\n"
using namespace std;
const int N = 555;
const int M = 2e5+100;
const int INF = 1e18;
const int mod = 998244353;
// int binpow (int a, int n) {
// if (n == 0)
// return 1;
// if (n % 2 == 1)
// return (binpow (a, n-1) * a)%mod;
// else {
// int b = binpow (a, n/2) % mod;
// return (b * b)%mod;
// }
// }
int n,m,k;
char a[N][N];
string s;
map<char,pair<int,int>> d;
bool ok;
void dfs(int v, int x, int y){
if(x<=0 || y<=0 || x>n || y>m || a[x][y] == '#') return;
if(v==k){
ok = 1;
return;
}
if(s[v] != '?'){
dfs(v+1,x+d[s[v]].ff,y+d[s[v]].ss);
}
else{
dfs(v+1,x+1,y);
dfs(v+1,x-1,y);
dfs(v+1,x,y+1);
dfs(v+1,x,y-1);
}
}
void solve(){
cin>>n>>m>>k;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>a[i][j];
}
}
cin>>s;
int ans = 0;
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
ok = 0;
dfs(0,i,j);
if(ok){
ans++;
}
}
}
cout<<ans<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
// cout.tie(nullptr);
d['N'].ff--;
d['W'].ss--;
d['S'].ff++;
d['E'].ss++;
int t = 1;
// cin>>t;
// cout<<"";
for(int i = 1;i<=t;i++){
solve();
// cout<<'\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |