結果

問題 No.130 XOR Minimax
ユーザー akakimidoriakakimidori
提出日時 2018-08-22 22:37:21
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 23 ms / 5,000 ms
コード長 681 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 29,532 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-10 00:22:56
合計ジャッジ時間 1,530 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
4,352 KB
testcase_01 AC 0 ms
4,352 KB
testcase_02 AC 0 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 11 ms
4,352 KB
testcase_05 AC 18 ms
4,352 KB
testcase_06 AC 14 ms
4,352 KB
testcase_07 AC 17 ms
4,352 KB
testcase_08 AC 18 ms
4,348 KB
testcase_09 AC 4 ms
4,352 KB
testcase_10 AC 6 ms
4,352 KB
testcase_11 AC 21 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 16 ms
4,352 KB
testcase_14 AC 23 ms
4,348 KB
testcase_15 AC 1 ms
4,352 KB
testcase_16 AC 15 ms
4,348 KB
testcase_17 AC 17 ms
4,348 KB
testcase_18 AC 18 ms
4,352 KB
testcase_19 AC 22 ms
4,352 KB
testcase_20 AC 11 ms
4,348 KB
testcase_21 AC 23 ms
4,352 KB
testcase_22 AC 5 ms
4,348 KB
testcase_23 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

int cmp(const void *a,const void *b){
  return *(int *)a-*(int *)b;
}

int calc(int *a,int n,int shift){
  if(n<=1) return 0;
  if(shift==0) return (a[0]&0x01)==(a[n-1]&0x01)?0:1;
  if(((a[0]>>shift)&0x01)==((a[n-1]>>shift)&0x01)) return calc(a,n,shift-1);
  int r;
  for(r=0;((a[r]>>shift)&0x01)==0;r++);
  int x=calc(a,r,shift-1);
  int y=calc(a+r,n-r,shift-1);
  return (1<<shift)+(x<y?x:y);
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  qsort(a,n,sizeof(int),cmp);
  int ans=calc(a,n,30);
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}
0