結果

問題 No.822 Bitwise AND
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-28 23:06:12
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 618 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 78,868 KB
最終ジャッジ日時 2023-09-08 13:40:32
合計ジャッジ時間 10,790 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 729 ms
77,216 KB
testcase_02 AC 71 ms
71,268 KB
testcase_03 AC 71 ms
71,212 KB
testcase_04 AC 98 ms
76,268 KB
testcase_05 AC 80 ms
76,256 KB
testcase_06 AC 85 ms
75,996 KB
testcase_07 AC 98 ms
76,180 KB
testcase_08 AC 85 ms
76,268 KB
testcase_09 AC 89 ms
76,152 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 86 ms
76,236 KB
testcase_13 AC 108 ms
76,148 KB
testcase_14 AC 71 ms
71,160 KB
testcase_15 AC 84 ms
75,832 KB
testcase_16 AC 1,829 ms
78,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

U = 19
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