Submission #832854

# Submission time Handle Problem Language Result Execution time Memory
832854 2023-08-21T15:59:52 Z serifefedartar Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 6644 KB
#include <bits/stdc++.h>
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
typedef long long ll;
#define f first
#define s second
#define MOD 1000000007
#define LOGN 20
#define MAXN 300005

vector<vector<bool>> in_set;
vector<string> grid;
int main() {
	fast
	int R, C, M;
	cin >> R >> C >> M;

	grid = vector<string>(R);
	in_set = vector<vector<bool>>(R, vector<bool>(C, false));
	for (int i = 0; i < R; i++)
		cin >> grid[i];
	string way;
	cin >> way;

	vector<pair<int,int>> curr;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (grid[i][j] == '.')
				curr.push_back({i, j});
		}
	}

	vector<pair<int,int>> new_curr;
	for (int i = 0; i < M; i++) {
		new_curr = vector<pair<int,int>>();
		for (auto u : curr)
			in_set[u.f][u.s] = false;

		if (way[i] == 'W') {
			for (auto u : curr) {
				if (u.s && grid[u.f][u.s-1] == '.' && !in_set[u.f][u.s-1]) {
					new_curr.push_back({u.f, u.s-1});
					in_set[u.f][u.s-1] = true;
				}
			}
		} else if (way[i] == 'E') {
			for (auto u : curr) {
				if (u.s != C-1 && grid[u.f][u.s+1] == '.' && !in_set[u.f][u.s+1]) {
					new_curr.push_back({u.f, u.s+1});
					in_set[u.f][u.s+1] = true;
				}
			}
		} else if (way[i] == 'N') {
			for (auto u : curr) {
				if (u.f && grid[u.f-1][u.s] == '.' && !in_set[u.f-1][u.s]) {
					new_curr.push_back({u.f-1, u.s});
					in_set[u.f-1][u.s] = true;
				}
			}
		} else if (way[i] == 'S') {
			for (auto u : curr) {
				if (u.f != R-1 && grid[u.f+1][u.s] == '.' && !in_set[u.f+1][u.s]) {
					new_curr.push_back({u.f+1, u.s});
					in_set[u.f+1][u.s] = true;
				}
			}
		} else {
			for (auto u : curr) {
				if (u.s && grid[u.f][u.s-1] == '.' && !in_set[u.f][u.s-1]) {
					new_curr.push_back({u.f, u.s-1});
					in_set[u.f][u.s-1] = true;
				}
				if (u.s != C-1 && grid[u.f][u.s+1] == '.' && !in_set[u.f][u.s+1]) {
					new_curr.push_back({u.f, u.s+1});
					in_set[u.f][u.s+1] = true;
				}
				if (u.f && grid[u.f-1][u.s] == '.' && !in_set[u.f-1][u.s]) {
					new_curr.push_back({u.f-1, u.s});
					in_set[u.f-1][u.s] = true;
				}
				if (u.f != R-1 && grid[u.f+1][u.s] == '.' && !in_set[u.f+1][u.s]) {
					new_curr.push_back({u.f+1, u.s});
					in_set[u.f+1][u.s] = true;
				}
			}
		}
		swap(curr, new_curr);
	}

	cout << curr.size() << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 644 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 644 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 12 ms 612 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 15 ms 648 KB Output is correct
13 Correct 13 ms 468 KB Output is correct
14 Correct 12 ms 548 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 14 ms 612 KB Output is correct
18 Correct 18 ms 520 KB Output is correct
19 Correct 9 ms 436 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 644 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 12 ms 612 KB Output is correct
8 Correct 5 ms 468 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 15 ms 648 KB Output is correct
13 Correct 13 ms 468 KB Output is correct
14 Correct 12 ms 548 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 14 ms 612 KB Output is correct
18 Correct 18 ms 520 KB Output is correct
19 Correct 9 ms 436 KB Output is correct
20 Correct 3 ms 340 KB Output is correct
21 Correct 0 ms 340 KB Output is correct
22 Execution timed out 1070 ms 6644 KB Time limit exceeded
23 Halted 0 ms 0 KB -