제출 #1148253

#제출 시각아이디문제언어결과실행 시간메모리
1148253adlinNautilus (BOI19_nautilus)C++20
29 / 100
3 ms832 KiB
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;

int r,c,n,ans;

string s;

char a[106][106];

set <pair<int,int>> st;

void rec(int ind, int x, int y){
	if(x <= 0 || x > r) return;
	if(y <= 0 || y > c) return;
	if(a[x][y] != '.') return;
	if(ind == n + 1){
		st.insert({x,y});
		return;
	}
	if(s[ind] == 'N'){
		rec(ind + 1, x - 1, y);
	}
	else if(s[ind] == 'E'){
		rec(ind + 1, x, y + 1);
	}
	else if(s[ind] == 'S'){
		rec(ind + 1, x + 1, y);
	}
	else {
		rec(ind + 1, x, y - 1);
	}
}

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> r >> c >> n;
	
	for(int i = 1; i <= r; i++){
		for(int j = 1; j <= c; j++){
			cin >> a[i][j];
		}
	}
	
	cin >> s;
	
	s = " " + s;
	
	for(int i = 1; i <= r; i++){
		for(int j = 1; j <= c; j++){
			if(a[i][j] == '.'){
				rec(1,i,j);
			}
		}
	}
	
	cout << st.size();
	
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...