結果

問題 No.130 XOR Minimax
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-07-01 12:44:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 199 ms / 5,000 ms
コード長 656 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,192 KB
実行使用メモリ 141,520 KB
最終ジャッジ日時 2023-09-10 10:25:45
合計ジャッジ時間 5,668 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
83,988 KB
testcase_01 AC 73 ms
71,428 KB
testcase_02 AC 73 ms
71,388 KB
testcase_03 AC 71 ms
71,532 KB
testcase_04 AC 90 ms
88,600 KB
testcase_05 AC 148 ms
141,520 KB
testcase_06 AC 174 ms
97,792 KB
testcase_07 AC 198 ms
118,528 KB
testcase_08 AC 176 ms
97,844 KB
testcase_09 AC 126 ms
78,344 KB
testcase_10 AC 136 ms
79,836 KB
testcase_11 AC 184 ms
93,992 KB
testcase_12 AC 121 ms
78,432 KB
testcase_13 AC 171 ms
89,604 KB
testcase_14 AC 199 ms
94,816 KB
testcase_15 AC 92 ms
76,500 KB
testcase_16 AC 169 ms
88,188 KB
testcase_17 AC 169 ms
88,540 KB
testcase_18 AC 177 ms
90,376 KB
testcase_19 AC 190 ms
92,940 KB
testcase_20 AC 147 ms
82,896 KB
testcase_21 AC 193 ms
94,524 KB
testcase_22 AC 126 ms
78,624 KB
testcase_23 AC 124 ms
78,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
def main1(n,a):
  def func(ary):
    # aryに対する答え
    mx=max(ary)
    if mx==0:return 0
    if len(ary)==1:return 0
    bit=1<<(mx.bit_length()-1)
    nary0=[]
    nary1=[]
    for x in ary:
      if x&bit:
        nary0.append(x^bit)
      else:
        nary1.append(x)
    ret=10**10
    for nary in [nary0,nary1]:
      if not nary:continue
      elif len(nary)==len(ary):
        ret=min(ret,func(nary))
      else:
        ret=min(ret,func(nary)+bit)
    return ret
  x=func(a)
  return x

if __name__=='__main__':
  n=int(input())
  a=list(map(int,input().split()))
  ret1=main1(n,a)
  print(ret1)
0