結果

問題 No.130 XOR Minimax
コンテスト
ユーザー LyricalMaestro
提出日時 2025-10-28 01:44:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 993 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,716 KB
実行使用メモリ 169,112 KB
最終ジャッジ日時 2025-10-28 01:44:21
合計ジャッジ時間 5,307 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 2 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://yukicoder.me/problems/no/1219

from collections import deque

def main():
    N = int(input())
    A = list(map(int, input().split()))


    def dfs(a_array, k):
        if len(a_array) == 0:
            return 0
        if k < 0:
            return 0

        count = [[], []]
        for a in a_array:
            if (1 << k) & a > 0:
                count[1].append(a)
            else:
                count[0].append(a)

        if len(count[0]) > 0 and len(count[1]) > 0:        
            answer = 1 << k
            ans0 = dfs(count[0], k - 1)
            ans1 = dfs(count[1], k - 1)
            answer += max(ans0, ans1)
        elif len(count[0]) > 0:
            answer = dfs(count[0], k - 1)
        elif len(count[1]) > 0:
            answer = dfs(count[1], k - 1)

        return answer

    max_a = max(A)
    k = 0
    while max_a > 0:
        k += 1
        max_a //= 2
    k += 1

    answer = dfs(A, k)
    print(answer)




if __name__ == "__main__":
    main()
0