結果

問題 No.939 and or
ユーザー FromBooskaFromBooska
提出日時 2023-03-07 18:58:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 40 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 81,636 KB
実行使用メモリ 53,408 KB
最終ジャッジ日時 2023-10-18 05:35:17
合計ジャッジ時間 2,427 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,408 KB
testcase_01 AC 39 ms
53,408 KB
testcase_02 AC 40 ms
53,408 KB
testcase_03 AC 38 ms
53,408 KB
testcase_04 AC 38 ms
53,408 KB
testcase_05 AC 39 ms
53,408 KB
testcase_06 AC 38 ms
53,408 KB
testcase_07 AC 38 ms
53,408 KB
testcase_08 AC 38 ms
53,408 KB
testcase_09 AC 38 ms
53,408 KB
testcase_10 AC 38 ms
53,408 KB
testcase_11 AC 39 ms
53,408 KB
testcase_12 AC 38 ms
53,408 KB
testcase_13 AC 38 ms
53,408 KB
testcase_14 AC 38 ms
53,408 KB
testcase_15 AC 39 ms
53,408 KB
testcase_16 AC 39 ms
53,408 KB
testcase_17 AC 39 ms
53,408 KB
testcase_18 AC 38 ms
53,408 KB
testcase_19 AC 38 ms
53,408 KB
testcase_20 AC 38 ms
53,408 KB
testcase_21 AC 38 ms
53,408 KB
testcase_22 AC 37 ms
53,408 KB
testcase_23 AC 38 ms
53,408 KB
testcase_24 AC 39 ms
53,408 KB
testcase_25 AC 37 ms
53,408 KB
testcase_26 AC 37 ms
53,408 KB
testcase_27 AC 38 ms
53,408 KB
testcase_28 AC 38 ms
53,408 KB
testcase_29 AC 38 ms
53,408 KB
testcase_30 AC 37 ms
53,408 KB
testcase_31 AC 39 ms
53,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# AND、つまりAの桁が1ならば、XもYもその桁は1
# OR、つまりBの桁が0ならば、XもYもその桁は0
# ここまでに矛盾があればそんなX, Yは存在しないので0
# 残りのありうる組合せはANDの桁が0でORの桁が1、逆はありえない
# ANDの桁が0でORの桁が1の数がn個なら、組合せ数は2**(n-1)ではないか

A, B = map(int, input().split())
#print(bin(A), bin(B))

test_from_A = True
A_len = len(bin(A))-2
for shift in range(A_len):
    if A>>shift & 1 == 1:
        if B>>shift & 1 != 1:
            test_from_A = False
test_from_B = True
B_len = len(bin(B))-2
for shift in range(B_len):
    if B>>shift & 1 != 1:
        if A>>shift & 1 == 1:
            test_from_B = False            
#print(test_from_A, test_from_B)
count = 0
max_len = max(A_len, B_len)
# A_lenで数え上げるとB_lenの方が長いときにミスる
for shift in range(max_len):
    if A>>shift & 1 != 1:
        if B>>shift & 1 == 1:
            count += 1
if test_from_A == True and test_from_B == True:
    ans = 2**(max(0, count-1))
    # max入れないと小数になってしまう、count=0、つまりA=Bのとき
    print(ans)
else:
    print(0)
0