Submission #925684

# Submission time Handle Problem Language Result Execution time Memory
925684 2024-02-12T07:26:05 Z vjudge1 Nautilus (BOI19_nautilus) C++17
66 / 100
1000 ms 1440 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[2][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] == '.') {
				used[0][i][j] = 1;
			}
		}
	}
	for(int id = 0; id < k; ++id) {
		for(int x = 1; x <= n; ++x) {
			for(int y = 1; y <= m; ++y) {
				if(!used[0][x][y]) {
					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] == '#') {
						continue;
					}
					used[1][tox][toy] = 1;
				}
			}
		}
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= m; ++j) {
				swap(used[0][i][j], used[1][i][j]);
				used[1][i][j] = 0;
			}
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= m; ++j) {
			ans += used[0][i][j];
		}
	}
	cout << ans << "\n";
	return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:82:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   82 |     for(auto e : dir[s[id+1]]) {
      |                             ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 12 ms 508 KB Output is correct
13 Correct 14 ms 348 KB Output is correct
14 Correct 12 ms 504 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 496 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 11 ms 348 KB Output is correct
20 Correct 3 ms 356 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 4 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 12 ms 508 KB Output is correct
13 Correct 14 ms 348 KB Output is correct
14 Correct 12 ms 504 KB Output is correct
15 Correct 2 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 17 ms 496 KB Output is correct
18 Correct 15 ms 348 KB Output is correct
19 Correct 11 ms 348 KB Output is correct
20 Correct 3 ms 356 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Execution timed out 1042 ms 1440 KB Time limit exceeded
23 Halted 0 ms 0 KB -