結果

問題 No.939 and or
ユーザー FromBooskaFromBooska
提出日時 2023-09-04 12:41:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 643 ms
コンパイル使用メモリ 86,768 KB
実行使用メモリ 71,356 KB
最終ジャッジ日時 2023-09-04 12:41:39
合計ジャッジ時間 4,440 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,216 KB
testcase_01 AC 73 ms
71,312 KB
testcase_02 AC 74 ms
71,232 KB
testcase_03 AC 72 ms
71,136 KB
testcase_04 AC 74 ms
71,224 KB
testcase_05 AC 74 ms
71,308 KB
testcase_06 AC 73 ms
71,120 KB
testcase_07 AC 74 ms
71,276 KB
testcase_08 AC 74 ms
71,312 KB
testcase_09 AC 73 ms
71,260 KB
testcase_10 AC 74 ms
71,320 KB
testcase_11 AC 74 ms
70,972 KB
testcase_12 AC 74 ms
71,356 KB
testcase_13 AC 74 ms
71,320 KB
testcase_14 AC 75 ms
71,300 KB
testcase_15 AC 73 ms
71,240 KB
testcase_16 AC 74 ms
71,068 KB
testcase_17 AC 74 ms
71,236 KB
testcase_18 AC 76 ms
71,244 KB
testcase_19 AC 73 ms
71,204 KB
testcase_20 AC 75 ms
71,240 KB
testcase_21 AC 75 ms
71,256 KB
testcase_22 AC 73 ms
70,996 KB
testcase_23 AC 73 ms
71,336 KB
testcase_24 AC 73 ms
70,996 KB
testcase_25 AC 74 ms
71,216 KB
testcase_26 AC 71 ms
71,004 KB
testcase_27 AC 74 ms
71,256 KB
testcase_28 AC 73 ms
71,260 KB
testcase_29 AC 71 ms
71,072 KB
testcase_30 AC 72 ms
71,252 KB
testcase_31 AC 78 ms
71,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# X&Y=Aより、aが1のとき、xもyも1
# X|Y=Bより、bが0のとき、xもyも0
# これによりX, Yの確定桁がわかる、残りの桁はどちらかが1でもう片方が0となる
# X<=Yより、未定桁の最初の数字はx=0, y=1となるしかない、両方が同じ数字には&, |の制約からなりえない
# 残りの未定桁数がdとすれば、パターン数は2**dとなるだろう
# 30桁でなく31桁調べるべきだった

A, B = map(int, input().split())
bit_1 = [-1]*31
bit_0 = [-1]*31
undecided = 0
for i in range(31):
    if A>>i&1 == 1:
        bit_1[i] = 1
    if B>>i&1 == 0:
        bit_0[i] = 0
    if bit_1[i] == -1 and bit_0[i] == -1:
        undecided += 1
    if bit_1[i] == 1 and bit_0[i] == 0:
        undecided -= 100
#print(bit_1)
#print(bit_0)
#print(undecided)

if undecided < 0:
    ans = 0
elif undecided == 0:
    ans = 1
else:
    ans = pow(2, undecided-1)
print(ans)
0