제출 #544440

#제출 시각아이디문제언어결과실행 시간메모리
544440rainboyBitwise (BOI06_bitwise)C11
100 / 100
0 ms340 KiB
#include <stdio.h>

#define N	100
#define L	30

int solve(int *aa, int *bb, int n, int *cc) {
	int l, i, c, cnt;

	c = 0, cnt = 0;
	for (l = L; l >= 0; l--) {
		int k0, k1, k01;

		k0 = k1 = k01 = 0;
		for (i = 0; i < n; i++)
			if ((bb[i] & 1 << l) == 0)
				k0++;
			else if ((aa[i] & 1 << l) != 0)
				k1++;
			else
				k01++;
		if (k01 == 0) {
			if (k1 > 0)
				c |= 1 << l;
			continue;
		}
		if (k01 > 1 || k1 > 0) {
			c |= (1LL << l + 1) - 1;
			break;
		}
		cc[cnt++] = c | (1 << l) - 1;
		c |= 1 << l;
		for (i = 0; i < n; i++)
			if ((aa[i] & 1 << l) == 0 && (bb[i] & 1 << l) != 0) {
				aa[i] = 0;
				break;
			}
	}
	cc[cnt++] = c;
	return cnt;
}

int main() {
	static int aa[N], bb[N], cc[N][L + 2], kk[N];
	int n, m, h, i, l, ans;

	scanf("%d%d", &n, &m);
	for (h = 0; h < m; h++)
		scanf("%d", &kk[h]);
	for (h = 0; h < m; h++) {
		for (i = 0; i < kk[h]; i++)
			scanf("%d%d", &aa[i], &bb[i]);
		kk[h] = solve(aa, bb, kk[h], cc[h]);
	}
	ans = 0;
	for (l = L; l >= 0; l--) {
		ans |= 1 << l;
		for (h = 0; h < m; h++) {
			int ok = 0;

			for (i = 0; i < kk[h]; i++)
				if ((cc[h][i] & ans) == ans) {
					ok = 1;
					break;
				}
			if (!ok) {
				ans ^= 1 << l;
				break;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bitwise.c: In function 'solve':
bitwise.c:27:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
   27 |    c |= (1LL << l + 1) - 1;
      |                 ~~^~~
bitwise.c:30:28: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   30 |   cc[cnt++] = c | (1 << l) - 1;
      |                   ~~~~~~~~~^~~
bitwise.c: In function 'main':
bitwise.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
bitwise.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d", &kk[h]);
      |   ^~~~~~~~~~~~~~~~~~~
bitwise.c:51:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |    scanf("%d%d", &aa[i], &bb[i]);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...