結果

問題 No.822 Bitwise AND
ユーザー bal4ubal4u
提出日時 2019-07-27 16:03:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 28,440 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 01:14:00
合計ジャッジ時間 1,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 0 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 0 ms
4,376 KB
testcase_15 AC 0 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.822 Bitwise AND
// 2019.7.27 bal4u

#include <stdio.h>

int N, K;
char b[20]; int w;
int ans;

void rec(int id, int x, int y) {
	if (id == w) {
		if (y >= x && (y|N) <= K + (x|N)) ans++;
		return;
	}
	if (b[id]) rec(id+1, x, y);
	else {
		rec(id+1, x, y);
		rec(id+1, x, y|(1<<id));
		rec(id+1, x|(1<<id), y);
	}
}

int main()
{
	int i, n, N, zero;

	scanf("%d%d", &N, &K);
	if (N < K) { puts("INF"); return 0; }
	ans = 1;
	if (K > 0) {
		zero = 0, n = N; for (w = 0; n; w++) {
			if (n & 1) b[w] = 1;
			else zero++;
			n >>= 1;
		}
		if (zero) {
			ans = 0, rec(0, 0, 0);
		}
	}
	printf("%d\n", ans);
	return 0;
}
0