Submission #752217

#TimeUsernameProblemLanguageResultExecution timeMemory
752217penguin133Nautilus (BOI19_nautilus)C++17
66 / 100
1072 ms73112 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int r, c, m;
bool ok[501][501][501];
char G[501][501];
string s;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

void solve(){
	cin >> r >> c >> m;
	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++)cin >> G[i][j];
	queue <pii> q;
	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++){
		if(G[i][j] == '.'){
			q.push({0, {i, j}});
		}
	}
	cin >> s;
	while(!q.empty()){
		int a = q.front().fi, x = q.front().se.fi, y = q.front().se.se;
		q.pop();
		if(a == m)continue;
		if(s[a] != '?'){
			if(s[a] == 'W'){
				if(y > 1 && G[x][y-1] != '#' && !ok[a+1][x][y-1])ok[a + 1][x][y - 1] = 1, q.push({a + 1, {x, y - 1}});
			}
			if(s[a] == 'E'){
				if(y < c && G[x][y+1] != '#' && !ok[a+1][x][y+1])ok[a + 1][x][y + 1] = 1, q.push({a + 1, {x, y + 1}});
			}
			if(s[a] == 'S'){
				if(x < r && G[x+1][y] != '#' && !ok[a+1][x+1][y])ok[a + 1][x + 1][y] = 1, q.push({a + 1, {x + 1, y}});
			}
			if(s[a] == 'N'){
				if(x > 1 && G[x-1][y] != '#' && !ok[a+1][x-1][y])ok[a + 1][x-1][y] = 1, q.push({a + 1, {x-1, y}});
			}
			continue;
		}
		for(int i = 0; i < 4; i++){
			int x1 = x + dx[i], y1 = y + dy[i];
			if(x1 < 1 || x1 > r || y1 < 1 || y1 > c || G[x1][y1] == '#' || ok[a+1][x1][y1])continue;
			ok[a+1][x1][y1] = 1; q.push({a+1, {x1, y1}});
		}
	}
	int ans = 0;
	for(int i=1;i<=r;i++)for(int j=1;j<=c;j++)ans += ok[m][i][j];
	cout << ans;
}

main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int tc = 1;
	//cin >> tc;
	for(int tc1=1;tc1<=tc;tc1++){
		// cout << "Case #" << tc1 << ": ";
		solve();
	}
}

Compilation message (stderr)

nautilus.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...