結果

問題 No.822 Bitwise AND
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-28 23:05:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 618 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 77,168 KB
最終ジャッジ日時 2023-09-08 13:39:51
合計ジャッジ時間 5,594 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 896 ms
77,064 KB
testcase_01 AC 297 ms
76,672 KB
testcase_02 AC 73 ms
71,332 KB
testcase_03 AC 72 ms
71,232 KB
testcase_04 AC 88 ms
76,168 KB
testcase_05 AC 78 ms
75,960 KB
testcase_06 AC 84 ms
76,328 KB
testcase_07 AC 89 ms
76,216 KB
testcase_08 AC 86 ms
75,976 KB
testcase_09 AC 85 ms
76,164 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 85 ms
76,232 KB
testcase_13 AC 94 ms
76,172 KB
testcase_14 AC 72 ms
71,196 KB
testcase_15 AC 81 ms
76,268 KB
testcase_16 AC 724 ms
77,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

U = 18
N, K = map(int, input().split())
if N == 0:
    if K == 0:
        print(1)
    else:
        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