結果
問題 |
No.939 and or
|
ユーザー |
![]() |
提出日時 | 2023-03-07 18:23:21 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,107 bytes |
コンパイル時間 | 626 ms |
コンパイル使用メモリ | 82,580 KB |
実行使用メモリ | 54,096 KB |
最終ジャッジ日時 | 2024-09-18 02:12:53 |
合計ジャッジ時間 | 2,619 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 WA * 5 |
ソースコード
# 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)