답안 #494180

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494180 2021-12-14T16:40:56 Z rainboy L-triominoes (CEOI21_ltriominoes) C
0 / 100
250 ms 436 KB
#include <stdio.h>
#include <string.h>

#define N	13
#define M	1000

void advance(char *dp, int n, int c) {
	static char dq[N][1 << N + 1];
	int i, b;

	for (i = 0; i < n; i++)
		memset(dq[i], 0, (1 << n + 1) * sizeof *dq[i]);
	for (b = 0; b < 1 << n; b++)
		if (dp[b]) {
			dq[0][b << 1 | (c & 1)] = 1;
			if ((c & 1) == 0 && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
				dq[0][b << 1 | 1 << n | 1 << n - 1 | 1 << 0] = 1;
		}
	for (i = 0; i + 1 < n; i++)
		for (b = 0; b < 1 << n + 1; b++)
			if (dq[i][b]) {
				int b_ = b << 1 & (1 << n + 1) - 1;

				if ((c & 1 << i + 1) != 0) {
					if ((b & 1 << n) != 0)
						dq[i + 1][b_ | 1 << 0] = 1;
				} else if ((b & 1 << n) != 0) {
					dq[i + 1][b_] = 1;
					if ((b & 1 << 0) == 0 && (b & 1 << n - 1) == 0)
						dq[i + 1][b_ | 1 << 0 | 1 << 1 | 1 << n] = 1;
					if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
						dq[i + 1][b_ | 1 << 0 | 1 << n - 1 | 1 << n] = 1;
				} else {
					if ((b & 1 << 0) == 0)
						dq[i + 1][b_ | 1 << 0 | 1 << 1] = 1;
					if ((b & 1 << n - 1) == 0)
						dq[i + 1][b_ | 1 << 0 | 1 << n] = 1;
					if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
						dq[i + 1][b_ | 1 << 0 | 1 << n - 1 | 1 << n] = 1;
				}
			}
	memset(dp, 0, (1 << n) * sizeof *dp);
	for (b = 0; b < 1 << n; b++)
		if (dq[n - 1][b | 1 << n])
			dp[b] = 1;
}

int main() {
	static char dp[1 << N];
	static int bb[M];
	int n, m, k, i, j;

	scanf("%d%d%d", &n, &m, &k);
	while (k--) {
		scanf("%d%d", &i, &j), i--, j--;
		bb[j] |= 1 << i;
	}
	dp[(1 << n) - 1] = 1;
	for (j = 0; j < m; j++)
		advance(dp, n, bb[j]);
	printf(dp[(1 << n) - 1] ? "YES\n" : "NO\n");
	return 0;
}

Compilation message

ltrominoes.c: In function 'advance':
ltrominoes.c:8:22: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
    8 |  static char dq[N][1 << N + 1];
      |                      ^~
ltrominoes.c:12:28: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   12 |   memset(dq[i], 0, (1 << n + 1) * sizeof *dq[i]);
      |                          ~~^~~
ltrominoes.c:16:36: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   16 |    if ((c & 1) == 0 && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                  ~~^~~
ltrominoes.c:16:61: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   16 |    if ((c & 1) == 0 && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                                           ~~^~~
ltrominoes.c:17:36: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   17 |     dq[0][b << 1 | 1 << n | 1 << n - 1 | 1 << 0] = 1;
      |                                  ~~^~~
ltrominoes.c:20:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   20 |   for (b = 0; b < 1 << n + 1; b++)
      |                        ~~^~~
ltrominoes.c:22:31: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   22 |     int b_ = b << 1 & (1 << n + 1) - 1;
      |                             ~~^~~
ltrominoes.c:22:36: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   22 |     int b_ = b << 1 & (1 << n + 1) - 1;
      |                       ~~~~~~~~~~~~~^~~
ltrominoes.c:24:21: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   24 |     if ((c & 1 << i + 1) != 0) {
      |                   ~~^~~
ltrominoes.c:29:43: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   29 |      if ((b & 1 << 0) == 0 && (b & 1 << n - 1) == 0)
      |                                         ~~^~~
ltrominoes.c:31:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   31 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                 ~~^~~
ltrominoes.c:31:60: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   31 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                                          ~~^~~
ltrominoes.c:32:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   32 |       dq[i + 1][b_ | 1 << 0 | 1 << n - 1 | 1 << n] = 1;
      |                                    ~~^~~
ltrominoes.c:36:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   36 |      if ((b & 1 << n - 1) == 0)
      |                    ~~^~~
ltrominoes.c:38:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   38 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                 ~~^~~
ltrominoes.c:38:60: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   38 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                                          ~~^~~
ltrominoes.c:39:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   39 |       dq[i + 1][b_ | 1 << 0 | 1 << n - 1 | 1 << n] = 1;
      |                                    ~~^~~
ltrominoes.c: In function 'main':
ltrominoes.c:53:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |  scanf("%d%d%d", &n, &m, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
ltrominoes.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 3 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 25 ms 436 KB Output is correct
9 Correct 4 ms 276 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 50 ms 412 KB Output is correct
12 Incorrect 11 ms 324 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 250 ms 288 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 276 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 3 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 25 ms 436 KB Output is correct
9 Correct 4 ms 276 KB Output is correct
10 Correct 3 ms 204 KB Output is correct
11 Correct 50 ms 412 KB Output is correct
12 Incorrect 11 ms 324 KB Output isn't correct
13 Halted 0 ms 0 KB -