結果

問題 No.822 Bitwise AND
ユーザー maspymaspy
提出日時 2020-02-25 23:59:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 824 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 10,836 KB
実行使用メモリ 33,832 KB
最終ジャッジ日時 2023-09-08 01:14:57
合計ジャッジ時間 8,504 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 814 ms
33,656 KB
testcase_01 AC 129 ms
29,736 KB
testcase_02 AC 129 ms
29,796 KB
testcase_03 AC 131 ms
29,812 KB
testcase_04 AC 824 ms
33,832 KB
testcase_05 AC 458 ms
33,676 KB
testcase_06 AC 719 ms
33,784 KB
testcase_07 AC 799 ms
33,796 KB
testcase_08 AC 133 ms
29,736 KB
testcase_09 AC 134 ms
29,732 KB
testcase_10 AC 139 ms
29,740 KB
testcase_11 AC 132 ms
29,780 KB
testcase_12 AC 140 ms
29,576 KB
testcase_13 AC 136 ms
30,248 KB
testcase_14 AC 132 ms
29,740 KB
testcase_15 AC 509 ms
33,804 KB
testcase_16 AC 134 ms
29,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
import numpy as np

# %%
N, K = map(int, read().split())


# %%
def solve_fixed_k(N, K):
    n = max(N, K).bit_length()
    x = np.arange(1 << n + 1, dtype=np.int32)
    y = x + K
    cond = (x & y == N)
    if np.any(cond & (x ^ y >= (1 << n))):
        return None
    else:
        return np.count_nonzero(cond)


# %%
answer = 0
for k in range(K + 1):
    x = solve_fixed_k(N, k)
    if x is None:
        answer = 'INF'
        break
    answer += x

# %%
print(answer)
0