답안 #544440

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
544440 2022-04-01T23:40:38 Z rainboy Bitwise (BOI06_bitwise) C
100 / 100
0 ms 340 KB
#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;
}

Compilation message

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]);
      |    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 288 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 284 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 288 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 0 ms 284 KB Output is correct
18 Correct 0 ms 288 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 292 KB Output is correct