結果

問題 No.130 XOR Minimax
ユーザー 👑 KazunKazun
提出日時 2022-12-11 03:42:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 166 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,596 KB
実行使用メモリ 91,116 KB
最終ジャッジ日時 2024-04-23 03:39:04
合計ジャッジ時間 3,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
80,872 KB
testcase_01 AC 38 ms
52,944 KB
testcase_02 AC 38 ms
52,872 KB
testcase_03 AC 37 ms
53,216 KB
testcase_04 AC 55 ms
77,072 KB
testcase_05 AC 63 ms
83,944 KB
testcase_06 AC 114 ms
90,052 KB
testcase_07 AC 121 ms
91,116 KB
testcase_08 AC 132 ms
90,808 KB
testcase_09 AC 97 ms
76,460 KB
testcase_10 AC 103 ms
77,552 KB
testcase_11 AC 121 ms
88,244 KB
testcase_12 AC 74 ms
75,988 KB
testcase_13 AC 115 ms
85,184 KB
testcase_14 AC 166 ms
89,020 KB
testcase_15 AC 45 ms
61,516 KB
testcase_16 AC 116 ms
84,276 KB
testcase_17 AC 134 ms
84,312 KB
testcase_18 AC 138 ms
85,496 KB
testcase_19 AC 131 ms
87,488 KB
testcase_20 AC 123 ms
80,812 KB
testcase_21 AC 136 ms
89,140 KB
testcase_22 AC 102 ms
76,916 KB
testcase_23 AC 74 ms
76,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search_Integer(L, R, cond, default=None):
    """ 条件式が単調増加であるとき, 整数上で二部探索を行う.

    L: 解の下限
    R: 解の上限
    cond: 条件(1変数関数, 広義単調増加を満たす)
    default: Lで条件を満たさないときの返り値
    """

    if not(cond(R)):
        return default

    if cond(L):
        return L

    R+=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C):
            R=C
        else:
            L=C
    return R

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

    A.sort()

    def bit(x,k):
        return (x>>k)&1

    def calc(l,r):
        if A[l]==A[r-1]:
            return 0

        k=(A[l]^A[r-1]).bit_length()-1
        i=General_Binary_Increase_Search_Integer(l,r-1, lambda i:bit(A[i],k))
        return (1<<k)+min(calc(l,i), calc(i,r))

    return calc(0,N)

#==================================================
print(solve())
0