結果

問題 No.939 and or
ユーザー FromBooskaFromBooska
提出日時 2023-03-07 18:23:21
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,107 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,916 KB
実行使用メモリ 53,848 KB
最終ジャッジ日時 2023-10-18 05:34:43
合計ジャッジ時間 3,013 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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**(count-1)
    print(ans)
else:
    print(0)
0