Submission #494177

# Submission time Handle Problem Language Result Execution time Memory
494177 2021-12-14T16:24:49 Z rainboy L-triominoes (CEOI21_ltriominoes) C
0 / 100
1 ms 464 KB
#include <stdio.h>
#include <stdlib.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]) {
			int b_ = 0;

			for (i = 0; i < n; i++)
				b_ = b_ << 1 | (b >> i & 1);
			dq[0][b_ << 1 | (c & 1)] = 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)
					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;
				}
			}
	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", &m, &n, &k);
	while (k--) {
		scanf("%d%d", &j, &i), 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:9:22: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
    9 |  static char dq[N][1 << N + 1];
      |                      ^~
ltrominoes.c:13:28: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   13 |   memset(dq[i], 0, (1 << n + 1) * sizeof *dq[i]);
      |                          ~~^~~
ltrominoes.c:23:26: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   23 |   for (b = 0; b < 1 << n + 1; b++)
      |                        ~~^~~
ltrominoes.c:25:31: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   25 |     int b_ = b << 1 & (1 << n + 1) - 1;
      |                             ~~^~~
ltrominoes.c:25:36: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   25 |     int b_ = b << 1 & (1 << n + 1) - 1;
      |                       ~~~~~~~~~~~~~^~~
ltrominoes.c:27:21: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   27 |     if ((c & 1 << i + 1) != 0)
      |                   ~~^~~
ltrominoes.c:31:43: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   31 |      if ((b & 1 << 0) == 0 && (b & 1 << n - 1) == 0)
      |                                         ~~^~~
ltrominoes.c:33:35: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   33 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                 ~~^~~
ltrominoes.c:33:60: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   33 |      if (i + 2 < n && (b & 1 << n - 1) == 0 && (b & 1 << n - 2) == 0)
      |                                                          ~~^~~
ltrominoes.c:34:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   34 |       dq[i + 1][b_ | 1 << 0 | 1 << n - 1 | 1 << n] = 1;
      |                                    ~~^~~
ltrominoes.c:38:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   38 |      if ((b & 1 << n - 1) == 0)
      |                    ~~^~~
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", &m, &n, &k);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
ltrominoes.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%d%d", &j, &i), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -