Submission #526215

#TimeUsernameProblemLanguageResultExecution timeMemory
526215Yazan_AlattarNautilus (BOI19_nautilus)C++14
100 / 100
151 ms632 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 505;
const ll inf = 2e9;
const ll mod = 998244353;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector < bitset <M> > dp(M);
bitset <M> a[M];
string s;
int n, m, ans, len;

int main()
{
	cin >> n >> m >> len;
	for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j){
		char c;
		cin >> c;
		if(c == '.') a[i][j] = 1, dp[i][j] = 1;
	}
	cin >> s;
	for(int i = 0; i < len; ++i){
		vector < bitset <M> > to(M);
		for(int j = 1; j <= n; ++j){
			if(s[i] == '?' || s[i] == 'N') to[j - 1] |= dp[j];
			if(s[i] == '?' || s[i] == 'S') to[j + 1] |= dp[j];
			if(s[i] == '?' || s[i] == 'E') to[j] |= (dp[j] << 1);
			if(s[i] == '?' || s[i] == 'W') to[j] |= (dp[j] >> 1);
		}
		dp = to;
		for(int j = 1; j <= n; ++j) dp[j] &= a[j];
	}
	for(int i = 1; i <= n; ++i) ans += dp[i].count();
	cout << ans << endl;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...