# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
544440 | rainboy | Bitwise (BOI06_bitwise) | C11 | 0 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |