답안 #544745

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544745 2022-04-02T16:25:26 Z rainboy Nautilus (BOI19_nautilus) C
100 / 100
251 ms 1100 KB
#include <stdio.h>
#include <string.h>

#define N	500
#define M	500
#define L	5000
#define B	60
#define K	4167	/* K = ceil(N * M / B) */

void and_(long long *aa, long long *bb, long long *cc) {
	int i;

	for (i = 0; i < K; i++)
		cc[i] = aa[i] & bb[i];
}

void or_(long long *aa, long long *bb, long long *cc) {
	int i;

	for (i = 0; i < K; i++)
		cc[i] = aa[i] | bb[i];
}

void shift_(long long *aa, int k) {
	int i, q, r;

	if (k > 0) {
		q = k / B, r = k % B;
		for (i = K - 1; i >= 0; i--) {
			long long a = aa[i];

			aa[i] = 0;
			if (i + q < K) {
				aa[i + q] |= (a & (1LL << B - r) - 1) << r;
				if (i + q + 1 < K)
					aa[i + q + 1] |= a >> B - r;
			}
		}
	} else {
		q = -k / B, r = -k % B;
		for (i = 0; i < K; i++) {
			long long a = aa[i];

			aa[i] = 0;
			if (i - q >= 0) {
				aa[i - q] |= a >> r;
				if (i - q > 0)
					aa[i - q - 1] |= (a & (1LL << r) - 1) << B - r;
			}
		}
	}
}

int main() {
	static char cc[N][M + 1], dd[L + 1];
	static long long aa[K], bb[K], tt[K], tt_[K], nn[K], ss[K], ww[K], ee[K];
	int n, m, l, h, i, j, ans;

	scanf("%d%d%d", &n, &m, &l);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++) {
			if (cc[i][j] == '.')
				aa[(i * m + j) / B] |= 1LL << (i * m + j) % B, bb[(i * m + j) / B] |= 1LL << (i * m + j) % B;
			if (i > 0)
				nn[(i * m + j) / B] |= 1LL << (i * m + j) % B;
			if (i + 1 < n)
				ss[(i * m + j) / B] |= 1LL << (i * m + j) % B;
			if (j > 0)
				ww[(i * m + j) / B] |= 1LL << (i * m + j) % B;
			if (j + 1 < m)
				ee[(i * m + j) / B] |= 1LL << (i * m + j) % B;
		}
	scanf("%s", dd);
	for (h = 0; h < l; h++)
		if (dd[h] == 'N')
			and_(aa, nn, tt), shift_(tt, -m), and_(tt, bb, aa);
		else if (dd[h] == 'S')
			and_(aa, ss, tt), shift_(tt, m), and_(tt, bb, aa);
		else if (dd[h] == 'W')
			and_(aa, ww, tt), shift_(tt, -1), and_(tt, bb, aa);
		else if (dd[h] == 'E')
			and_(aa, ee, tt), shift_(tt, 1), and_(tt, bb, aa);
		else {
			memset(tt_, 0, sizeof tt_);
			and_(aa, nn, tt), shift_(tt, -m), or_(tt_, tt, tt_);
			and_(aa, ss, tt), shift_(tt, m), or_(tt_, tt, tt_);
			and_(aa, ww, tt), shift_(tt, -1), or_(tt_, tt, tt_);
			and_(aa, ee, tt), shift_(tt, 1), or_(tt_, tt, tt_);
			and_(tt_, bb, aa);
		}
	ans = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (aa[(i * m + j) / B] & 1LL << (i * m + j) % B)
				ans++;
	printf("%d\n", ans);
	return 0;
}

Compilation message

nautilus.c: In function 'shift_':
nautilus.c:34:33: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   34 |     aa[i + q] |= (a & (1LL << B - r) - 1) << r;
      |                                 ^
nautilus.c:34:38: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   34 |     aa[i + q] |= (a & (1LL << B - r) - 1) << r;
      |                       ~~~~~~~~~~~~~~~^~~
nautilus.c:36:30: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   36 |      aa[i + q + 1] |= a >> B - r;
      |                              ^
nautilus.c:48:39: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   48 |      aa[i - q - 1] |= (a & (1LL << r) - 1) << B - r;
      |                            ~~~~~~~~~~~^~~
nautilus.c:48:49: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   48 |      aa[i - q - 1] |= (a & (1LL << r) - 1) << B - r;
      |                                                 ^
nautilus.c: In function 'main':
nautilus.c:59:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |  scanf("%d%d%d", &n, &m, &l);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
nautilus.c:61:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
nautilus.c:75:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  scanf("%s", dd);
      |  ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 424 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 424 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 476 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 432 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 4 ms 476 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 6 ms 472 KB Output is correct
21 Correct 7 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 2 ms 424 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 408 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 3 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 3 ms 468 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 476 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 4 ms 432 KB Output is correct
15 Correct 5 ms 468 KB Output is correct
16 Correct 4 ms 476 KB Output is correct
17 Correct 5 ms 468 KB Output is correct
18 Correct 6 ms 468 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 6 ms 472 KB Output is correct
21 Correct 7 ms 476 KB Output is correct
22 Correct 147 ms 1040 KB Output is correct
23 Correct 113 ms 1020 KB Output is correct
24 Correct 114 ms 1024 KB Output is correct
25 Correct 122 ms 1044 KB Output is correct
26 Correct 110 ms 1004 KB Output is correct
27 Correct 180 ms 1024 KB Output is correct
28 Correct 197 ms 980 KB Output is correct
29 Correct 184 ms 1024 KB Output is correct
30 Correct 180 ms 1028 KB Output is correct
31 Correct 187 ms 1008 KB Output is correct
32 Correct 240 ms 1020 KB Output is correct
33 Correct 240 ms 1024 KB Output is correct
34 Correct 232 ms 980 KB Output is correct
35 Correct 251 ms 1100 KB Output is correct
36 Correct 228 ms 1012 KB Output is correct