답안 #832862

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
832862 2023-08-21T16:04:32 Z serifefedartar Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 6748 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
#pragma GCC optimize("Ofast")

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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 644 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 644 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 3 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 1 ms 340 KB Output is correct
12 Correct 10 ms 644 KB Output is correct
13 Correct 13 ms 468 KB Output is correct
14 Correct 12 ms 556 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 11 ms 644 KB Output is correct
18 Correct 16 ms 468 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 644 KB Output is correct
2 Correct 1 ms 452 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 8 ms 632 KB Output is correct
8 Correct 3 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 1 ms 340 KB Output is correct
12 Correct 10 ms 644 KB Output is correct
13 Correct 13 ms 468 KB Output is correct
14 Correct 12 ms 556 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 11 ms 644 KB Output is correct
18 Correct 16 ms 468 KB Output is correct
19 Correct 9 ms 332 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Execution timed out 1065 ms 6748 KB Time limit exceeded
23 Halted 0 ms 0 KB -