結果

問題 No.130 XOR Minimax
ユーザー 👑 rin204
提出日時 2022-07-08 09:58:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 224 ms / 5,000 ms
コード長 431 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 81,792 KB
実行使用メモリ 141,312 KB
最終ジャッジ日時 2024-12-26 08:58:46
合計ジャッジ時間 5,068 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
A = list(set(map(int, input().split())))

def dfs(A, t):
    if len(A) == 1 or t == -1:
        return 0

    L = []
    R = []
    for a in A:
        if a >> t & 1:
            L.append(a ^ (1 << t))
        else:
            R.append(a)
    if L and R:
        return min(dfs(L, t - 1), dfs(R, t - 1)) | (1 << t)
    elif L:
        return dfs(L, t - 1)
    else:
        return dfs(R, t - 1)

print(dfs(A, 29))
0