結果

問題 No.130 XOR Minimax
ユーザー akakimidoriakakimidori
提出日時 2017-06-18 07:17:51
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 324 ms / 5,000 ms
コード長 1,272 bytes
コンパイル時間 1,444 ms
コンパイル使用メモリ 26,376 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-10 00:19:26
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
4,376 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 0 ms
4,368 KB
testcase_04 AC 11 ms
4,372 KB
testcase_05 AC 17 ms
4,372 KB
testcase_06 AC 154 ms
4,372 KB
testcase_07 AC 151 ms
4,368 KB
testcase_08 AC 324 ms
4,368 KB
testcase_09 AC 17 ms
4,372 KB
testcase_10 AC 31 ms
4,372 KB
testcase_11 AC 128 ms
4,368 KB
testcase_12 AC 6 ms
4,372 KB
testcase_13 AC 104 ms
4,372 KB
testcase_14 AC 274 ms
4,368 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 156 ms
4,376 KB
testcase_17 AC 164 ms
4,376 KB
testcase_18 AC 186 ms
4,372 KB
testcase_19 AC 243 ms
4,372 KB
testcase_20 AC 80 ms
4,368 KB
testcase_21 AC 268 ms
4,368 KB
testcase_22 AC 25 ms
4,372 KB
testcase_23 AC 4 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define MIN(a,b) ((a)<(b)?(a):(b))

void msort(int *a,int n,int *merge){
  if(n<=16){
    int i,j;
    for(i=1;i<n;i++){
      int p=a[i];
      j=i-1;
      while(j>=0 && p<a[j]){
	a[j+1]=a[j];
	j--;
      }
      a[j+1]=p;
    }
    return;
  }

  int m=n/2;
  msort(a,m,merge);
  msort(a+m,n-m,merge);

  int i,j,k;
  i=0;
  j=m;
  k=0;
  while(i<m && j<n){
    if(a[i]<=a[j]){
      merge[k++]=a[i++];
    } else {
      merge[k++]=a[j++];
    }
  }
  while(i<m) merge[k++]=a[i++];
  while(j<n) merge[k++]=a[j++];

  for(i=0;i<n;i++) a[i]=merge[i];
  return;
}

int calc(int *array,int n,int shift){
  if(n<=1) return 0;
  if(shift==0) return (array[0]&0x01)!=(array[n-1]&0x01);
  if(((array[0]>>shift)&0x01) == ((array[n-1]>>shift)&0x01)) return calc(array,n,shift-1);

  int r;
  for(r=1;((array[r]>>shift)&0x01)==0;r++);

  return (1<<shift)+MIN(calc(array,r,shift-1),calc(array+r,n-r,shift-1));
}

void run(void){
  int n;
  scanf("%d",&n);
  int *array=(int *)malloc(sizeof(int)*n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d",array+i);
  }
  int *merge=(int *)malloc(sizeof(int)*n);
  msort(array,n,merge);
  free(merge);
  int ans=calc(array,n,30);
  printf("%d\n",ans);
  return;
}

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