Submission #925662

# Submission time Handle Problem Language Result Execution time Memory
925662 2024-02-12T07:08:07 Z vjudge1 Nautilus (BOI19_nautilus) C++17
66 / 100
147 ms 262144 KB
#include<iostream>
#include<cassert>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#include<set>
#include<queue>
#include<map>

using namespace std;

const int N = (int)4e5 + 7;
const int inf = (int)1e9 + 7;
const int MOD = (int)998244353;
const long long INF = (long long)1e18 + 7; 

int mult(int x, int y) {
	return 1ll*x*y%MOD;
}

int sum(int x, int y) {
	x += y;
	if(x >= MOD) {
		x -= MOD;
	}
	return x;
}

int sub(int x, int y) {
	x -= y;
	if(x < 0) {
		x += MOD;
	}
	return x;
}

int n, m, k;

vector<pair<int, int> > dir[300];

void init() {
	dir['W'] = {{0, -1}};
	dir['E'] = {{0, +1}};
	dir['N'] = {{-1, 0}};
	dir['S'] = {{+1, 0}};
	dir['?'] = {{0, -1}, {0, +1}, {-1, 0}, {+1, 0}};
}

int main() {	
	ios_base::sync_with_stdio(NULL);
	cin.tie(0);
	init();
	cin >> n >> m >> k;
	char a[n+1][m+1];
	bool is[n+1][m+1];
	bool used[k+1][n+1][m+1];
	memset(used, 0, sizeof(used));
	memset(is, 0, sizeof(is));
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
		}
	}
	string s;
	cin >> s;
	s = '#'+s;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			if(a[i][j] == '#') {
				continue;
			}
			queue<pair<int, pair<int, int> > > q;
			q.push({0, {i, j}});
			used[0][i][j] = 1;
			while(!q.empty()) {
				int x = q.front().second.first;
				int y = q.front().second.second;
			    int id = q.front().first;
				q.pop();
				if(id == k) {
					is[x][y] = 1;
					continue;
				}
				for(auto e : dir[s[id+1]]) {
					int tox = x+e.first;
					int toy = y+e.second;
					if(tox<1 || tox>n || toy<1 || toy>m || a[tox][toy] == '#' || used[id+1][tox][toy]) {
						continue;
					}
					used[id+1][tox][toy] = 1;
					q.push({id+1, {tox, toy}});
				}
			}					
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			ans += is[i][j];
		}
	}
	cout << ans << "\n";
	return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:86:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   86 |     for(auto e : dir[s[id+1]]) {
      |                             ^
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 22 ms 1368 KB Output is correct
8 Correct 5 ms 1624 KB Output is correct
9 Correct 2 ms 1368 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1368 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 21 ms 1372 KB Output is correct
14 Correct 16 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1624 KB Output is correct
17 Correct 24 ms 1520 KB Output is correct
18 Correct 23 ms 1372 KB Output is correct
19 Correct 8 ms 1372 KB Output is correct
20 Correct 4 ms 1372 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1372 KB Output is correct
2 Correct 2 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 2 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 22 ms 1368 KB Output is correct
8 Correct 5 ms 1624 KB Output is correct
9 Correct 2 ms 1368 KB Output is correct
10 Correct 1 ms 1368 KB Output is correct
11 Correct 1 ms 1368 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 21 ms 1372 KB Output is correct
14 Correct 16 ms 1372 KB Output is correct
15 Correct 2 ms 1372 KB Output is correct
16 Correct 1 ms 1624 KB Output is correct
17 Correct 24 ms 1520 KB Output is correct
18 Correct 23 ms 1372 KB Output is correct
19 Correct 8 ms 1372 KB Output is correct
20 Correct 4 ms 1372 KB Output is correct
21 Correct 1 ms 1372 KB Output is correct
22 Runtime error 147 ms 262144 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -