結果

問題 No.130 XOR Minimax
ユーザー WSKRWSKR
提出日時 2020-09-23 15:12:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 302 ms / 5,000 ms
コード長 751 bytes
コンパイル時間 371 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 19,460 KB
最終ジャッジ日時 2023-10-10 00:29:33
合計ジャッジ時間 5,180 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
12,736 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 16 ms
7,892 KB
testcase_03 AC 16 ms
7,888 KB
testcase_04 AC 235 ms
9,992 KB
testcase_05 AC 202 ms
19,004 KB
testcase_06 AC 302 ms
19,460 KB
testcase_07 AC 250 ms
18,808 KB
testcase_08 AC 211 ms
19,192 KB
testcase_09 AC 61 ms
9,804 KB
testcase_10 AC 87 ms
10,652 KB
testcase_11 AC 301 ms
17,680 KB
testcase_12 AC 37 ms
8,932 KB
testcase_13 AC 225 ms
15,712 KB
testcase_14 AC 226 ms
17,460 KB
testcase_15 AC 18 ms
7,836 KB
testcase_16 AC 161 ms
14,376 KB
testcase_17 AC 166 ms
14,808 KB
testcase_18 AC 181 ms
15,404 KB
testcase_19 AC 219 ms
16,672 KB
testcase_20 AC 105 ms
12,276 KB
testcase_21 AC 228 ms
17,080 KB
testcase_22 AC 55 ms
9,920 KB
testcase_23 AC 27 ms
8,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#xor minimax
def main():
    N = int(input())
    a = list(map(int, input().split()))
    a.sort()
    def solve(order, l, r):
        if order == -1:
            return 0
        if l > r:
            return 10**20
        
        if l == r:
            return 0
        else:
            new_r = r + 1
            for i in range(l, r+1):
                if (a[i]>> order) & 1:
                    new_r = i
                    break
         
            if l < new_r < r + 1:
                return min(solve(order-1, l, new_r-1), solve(order-1, new_r, r)) + (1 << order)
            else:
                return solve(order-1, l, r)
                

    ans = solve(30, 0, N-1)
    print(ans)
    return


if __name__ == "__main__":
    main()

0