結果
問題 | No.130 XOR Minimax |
ユーザー |
👑 ![]() |
提出日時 | 2022-12-11 03:42:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 166 ms / 5,000 ms |
コード長 | 982 bytes |
コンパイル時間 | 167 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 90,916 KB |
最終ジャッジ日時 | 2024-10-15 03:11:21 |
合計ジャッジ時間 | 4,326 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 |
ソースコード
def General_Binary_Increase_Search_Integer(L, R, cond, default=None):""" 条件式が単調増加であるとき, 整数上で二部探索を行う.L: 解の下限R: 解の上限cond: 条件(1変数関数, 広義単調増加を満たす)default: Lで条件を満たさないときの返り値"""if not(cond(R)):return defaultif cond(L):return LR+=1while R-L>1:C=L+(R-L)//2if cond(C):R=Celse:L=Creturn Rdef solve():N=int(input())A=list(map(int,input().split()))A.sort()def bit(x,k):return (x>>k)&1def calc(l,r):if A[l]==A[r-1]:return 0k=(A[l]^A[r-1]).bit_length()-1i=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())