Submission #125496

#TimeUsernameProblemLanguageResultExecution timeMemory
125496mechfrog88Nautilus (BOI19_nautilus)C++14
100 / 100
271 ms157568 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll r,c,m;
	cin >> r >> c >> m;
	vector <string> grid(r);
	for (int z=0;z<r;z++){
		cin >> grid[z];
	}
	string signal;
	cin >> signal;
	bitset<500> dp[m+1][r];
	bitset<500> g[r];
	for (int j=0;j<r;j++){
		for (int k=0;k<c;k++){
			if (grid[j][k] == '#') {g[j][k] = 0; dp[0][j][k] = 0;}
			else {g[j][k] = 1 ; dp[0][j][k] = 1;}
		}
	}
	for (int i=1;i<=m;i++){
		char now = signal[i-1];
		for (int j=0;j<r;j++){
			if (now == 'W')	{
				dp[i][j] = dp[i-1][j] >> 1 & g[j];
			}
			if (now == 'E')	{
				dp[i][j] = dp[i-1][j] << 1 & g[j];
			}
			if (now == 'S' && j > 0){
				dp[i][j] = dp[i-1][j-1] & g[j];
			}
			if (now == 'N' && j < r-1){
				dp[i][j] = dp[i-1][j+1] & g[j];
			}
			if (now == '?'){
				if (j > 0) dp[i][j-1] |= (dp[i-1][j] | dp[i][j-1]) & g[j-1];
				if (j < r-1) dp[i][j+1] |= (dp[i-1][j] | dp[i][j+1]) & g[j+1];
				dp[i][j] |= (dp[i-1][j]<< 1) | (dp[i-1][j] >> 1) & g[j];
				dp[i][j] &= g[j];
			}
		}
	}
	ll ans = 0;
	for (int z=0;z<r;z++){
		for (int x=0;x<c;x++){
			if (dp[m][z][x]) ans++;
		}
	}
	cout << ans << endl;
}

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:53:54: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
     dp[i][j] |= (dp[i-1][j]<< 1) | (dp[i-1][j] >> 1) & g[j];
                                    ~~~~~~~~~~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...