Submission #1367037

#TimeUsernameProblemLanguageResultExecution timeMemory
1367037gvancakNautilus (BOI19_nautilus)C++20
29 / 100
4 ms344 KiB
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;
const ll N=105,INF=1e12;
ll ans,c[N],b[N][N],n,k,m,q;
char a[N][N];
pair <ll,ll> p[N];
bool ok;
string s;
pair<ll,ll> check(int i1,int j1,int k){
	if (i1<1 || i1>n || j1<1 || j1>m) return mp(0ll,0ll);
	if (a[i1][j1]!='.') return mp(0ll,0ll);
	int x=i1,y=j1;
	if (k==s.size()) return mp(x,y);
	if (s[k]=='N') x--;
	if (s[k]=='S') x++;
	if (s[k]=='E') y++;
	if (s[k]=='W') y--;
	pair <ll,ll> gg;
	if (s[k]=='?'){
		x--; gg=check(x,y,k+1);
		if (gg.f!=0) return gg;
		x++;
		x++; gg=check(x,y,k+1);
		if (gg.f!=0) return gg;
		x--;
		y--; gg=check(x,y,k+1);
		if (gg.f!=0) return gg;
		y++;
		y++; gg=check(x,y,k+1);
		if (gg.f!=0) return gg;
		y--;
		return mp(0ll,0ll);
	}
	return check(x,y,k+1);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    
    cin >> n >> m >> q;
    for (int i=1; i<=n; i++){
    	for (int j=1; j<=m; j++){
    		cin >> a[i][j];
		}
	}
	cin >> s;
	pair <ll,ll> g;
	for (int i=1; i<=n; i++){
		for (int j=1; j<=m; j++){
			g=check(i,j,0);
			if (g.f!=0){
				if (b[g.f][g.s]==0) ans++;
				b[g.f][g.s]=1;
			}
		}
	}
	cout << ans << endl;

}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...