#define L 12
#define N 924 /* N = choose(L, L / 2) */
static int cnt[1 << L], bb[N], n;
void init() {
int b;
n = 0;
cnt[0] = 0;
for (b = 1; b < 1 << L; b++)
if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
bb[n++] = b;
}
int encode(int n, int x, int y) {
int l;
init();
x--, y--;
for (l = 0; l < L; l++)
if ((bb[x] & 1 << l) == 0 && (bb[y] & 1 << l) != 0)
return l + 1;
return 0;
}
#define L 12
#define N 924 /* N = choose(L, L / 2) */
static int cnt[1 << L], bb[N], n;
void init() {
int b;
n = 0;
cnt[0] = 0;
for (b = 1; b < 1 << L; b++)
if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
bb[n++] = b;
}
int decode(int n, int x, int y) {
init();
x--, y--;
return (bb[x] & 1 << y) == 0;
}
Compilation message
encoder.c: In function 'init':
encoder.c:12:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
12 | if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
| ~~^~~
decoder.c: In function 'init':
decoder.c:12:27: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
12 | if ((cnt[b] = cnt[b & b - 1] + 1) == L / 2)
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
7062 ms |
8972 KB |
Time limit exceeded |
2 |
Execution timed out |
7034 ms |
8820 KB |
Time limit exceeded |