結果

問題 No.130 XOR Minimax
コンテスト
ユーザー akakimidori
提出日時 2018-08-22 22:37:21
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 681 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 206 ms
コンパイル使用メモリ 39,616 KB
最終ジャッジ日時 2026-02-22 01:30:07
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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