Submission #331670

# Submission time Handle Problem Language Result Execution time Memory
331670 2020-11-29T13:10:50 Z soroush Nautilus (BOI19_nautilus) C++14
100 / 100
43 ms 1004 KB
//*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn  = 510;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);
 
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}
 
int n , m , t;
string s[maxn];
string p;

bitset < maxn > block[maxn] , dp[2][maxn];

int32_t main(){
    migmig;
	cin >> n >> m >> t;
	for(int i = 0 ; i < n ; i  ++)
		cin >> s[i];
	cin >> p;
	for(int i = 1 ; i <= n ; i ++)
		for(int j = 1; j <= m ; j ++)
			if(s[i - 1][j - 1] == '.')block[i][j] = dp[0][i][j] = 1;
	for(int j = 0 ; j < t ; j ++){
		char cur = p[j];
		for(int i = 1 ; i <= n ; i ++){
			if(cur == 'S')
				dp[1-(j%2)][i] = dp[j%2][i-1]&block[i]; 
			if(cur == 'N')
				dp[1-(j%2)][i] = dp[j%2][i+1]&block[i];
			if(cur == 'W')
				dp[1-(j%2)][i] = (dp[j%2][i] >> 1)&block[i];
			if(cur == 'E')
				dp[1-(j%2)][i] = (dp[j%2][i] << 1)&block[i];
			if(cur == '?')
				dp[1-(j%2)][i] = ((dp[j%2][i] << 1) | (dp[j%2][i] >> 1) | dp[j%2][i+1] | dp[j%2][i-1])&block[i];
		}
	}
	ll ans = 0;
	for(int i = 1 ; i <= n ; i ++)
		ans += dp[t%2][i].count();
	cout << ans;
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 18 ms 748 KB Output is correct
23 Correct 22 ms 748 KB Output is correct
24 Correct 19 ms 892 KB Output is correct
25 Correct 21 ms 748 KB Output is correct
26 Correct 18 ms 748 KB Output is correct
27 Correct 26 ms 748 KB Output is correct
28 Correct 27 ms 876 KB Output is correct
29 Correct 30 ms 748 KB Output is correct
30 Correct 32 ms 748 KB Output is correct
31 Correct 26 ms 876 KB Output is correct
32 Correct 33 ms 748 KB Output is correct
33 Correct 43 ms 1004 KB Output is correct
34 Correct 33 ms 748 KB Output is correct
35 Correct 32 ms 748 KB Output is correct
36 Correct 32 ms 748 KB Output is correct