結果

問題 No.822 Bitwise AND
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-28 23:11:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,826 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 87,116 KB
実行使用メモリ 78,096 KB
最終ジャッジ日時 2023-09-08 13:46:03
合計ジャッジ時間 7,386 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 900 ms
77,116 KB
testcase_01 AC 293 ms
76,660 KB
testcase_02 AC 1,826 ms
78,096 KB
testcase_03 AC 70 ms
71,148 KB
testcase_04 AC 91 ms
75,980 KB
testcase_05 AC 81 ms
75,772 KB
testcase_06 AC 81 ms
76,184 KB
testcase_07 AC 88 ms
75,764 KB
testcase_08 AC 84 ms
76,020 KB
testcase_09 AC 83 ms
76,136 KB
testcase_10 AC 70 ms
71,028 KB
testcase_11 AC 69 ms
71,144 KB
testcase_12 AC 83 ms
76,188 KB
testcase_13 AC 95 ms
76,184 KB
testcase_14 AC 71 ms
71,104 KB
testcase_15 AC 84 ms
75,952 KB
testcase_16 AC 730 ms
77,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

U = 18
N, K = map(int, input().split())
if N < K:
    print("INF")
    exit()

bit = []
for i in reversed(range(U)):
    if ~(N >> i) & 1:
        bit.append(1 << i)
bit.reverse()

sz = len(bit)
val = [0] * (1 << sz)
for S in range(1 << sz):
    for i, b in enumerate(bit):
        if (S >> i) & 1:
            val[S] += b

ans = 0
mask_all = (1 << sz) - 1
for S, x in enumerate(val):
    T = mask_all ^ S
    mask = T
    while True:
        if 0 <= x - val[mask] <= K:
            ans += 1
        if not mask:
            break
        mask = (mask - 1) & T
print(ans)
0