結果

問題 No.130 XOR Minimax
ユーザー akakimidoriakakimidori
提出日時 2017-06-18 07:05:09
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,352 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-04-08 22:03:57
合計ジャッジ時間 11,254 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 0 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 12 ms
6,548 KB
testcase_05 AC 17 ms
6,548 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:63:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   63 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:67:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |     scanf("%d",array+i);
      |     ^~~~~~~~~~~~~~~~~~~

ソースコード

diff #

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

#define MAX(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 l=0;
  int r=n;
  while(l+1<r){
    int m=(l+r)/2;
    if((array[m]>>shift)&0x01){
      r=m;
    } else {
      l=m;
    }
  }
  return (1<<shift)+MAX(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