結果

問題 No.1957 Xor Min
ユーザー lam6er
提出日時 2025-03-20 20:33:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,099 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 82,792 KB
実行使用メモリ 60,168 KB
最終ジャッジ日時 2025-03-20 20:33:59
合計ジャッジ時間 2,274 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

def has_bit_zero(low, high, i):
    if low > high:
        return False
    mask = 1 << i
    max_zero = mask - 1
    return low <= max_zero and high >= low

def has_bit_one(low, high, i):
    if low > high:
        return False
    mask = 1 << i
    return high >= max(low, mask)

def max_xor(low_x, high_x, low_y, high_y):
    if low_x > high_x or low_y > high_y:
        return -1  # No possible XOR
    result = 0
    for i in reversed(range(32)):  # Assuming 32-bit integers
        mask = 1 << i
        candidate = result | mask
        can_0_1 = has_bit_zero(low_x, high_x, i) and has_bit_one(low_y, high_y, i)
        can_1_0 = has_bit_one(low_x, high_x, i) and has_bit_zero(low_y, high_y, i)
        if can_0_1 or can_1_0:
            result = candidate
    return result

A, B = map(int, input().split())

low = 0
high = min(A, B)
ans = 0
while low <= high:
    mid = (low + high) // 2
    x_low, x_high = mid, A
    y_low, y_high = mid, B
    mx = max_xor(x_low, x_high, y_low, y_high)
    if mx >= mid:
        ans = mid
        low = mid + 1
    else:
        high = mid - 1
print(ans)
0