結果

問題 No.497 入れ子の箱
ユーザー akakimidoriakakimidori
提出日時 2017-04-24 17:38:14
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 1,142 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 25,608 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-11 13:12:49
合計ジャッジ時間 1,716 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 8 ms
4,352 KB
testcase_05 AC 7 ms
4,356 KB
testcase_06 AC 7 ms
4,352 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 7 ms
4,352 KB
testcase_10 AC 7 ms
4,372 KB
testcase_11 AC 7 ms
4,356 KB
testcase_12 AC 9 ms
4,352 KB
testcase_13 AC 9 ms
4,372 KB
testcase_14 AC 9 ms
4,352 KB
testcase_15 AC 9 ms
4,352 KB
testcase_16 AC 9 ms
4,348 KB
testcase_17 AC 9 ms
4,352 KB
testcase_18 AC 7 ms
4,352 KB
testcase_19 AC 8 ms
4,356 KB
testcase_20 AC 7 ms
4,352 KB
testcase_21 AC 8 ms
4,348 KB
testcase_22 AC 7 ms
4,352 KB
testcase_23 AC 2 ms
4,352 KB
testcase_24 AC 2 ms
4,356 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 7 ms
4,352 KB
testcase_28 AC 7 ms
4,352 KB
testcase_29 AC 8 ms
4,352 KB
testcase_30 AC 6 ms
4,348 KB
testcase_31 AC 5 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define POS(index,kind) ((kind)*n+(index))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

int comp(int* array,int n,int i,int j){
  int k;
  for(k=0;k<3;k++){
    if(array[POS(i,k)]<=array[POS(j,k)]){
      return 0;
    }
  }
  return 1;
}

int calc(int i,int *array,int n,int *res){
  if(res[i]>0) return res[i];
  int j;
  int flag=1;
  for(j=0;j<n;j++){
    if(comp(array,n,i,j)){
      flag=0;
      res[i]=MAX(res[i],1+calc(j,array,n,res));
    }
  }
  if(flag){
    res[i]=1;
  }
  return res[i];
}

void run(void){
  int n;
  scanf("%d",&n);
  int *array=(int *)malloc(sizeof(int)*n*3);
  int i;
  for(i=0;i<n;i++){
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);
    array[POS(i,0)]=MAX(x,MAX(y,z));
    array[POS(i,2)]=MIN(x,MIN(y,z));
    array[POS(i,1)]=x+y+z-array[POS(i,0)]-array[POS(i,2)];
  }
  int *res=(int *)calloc(n,sizeof(int));
  for(i=0;i<n;i++){
    if(res[i]>0)
      continue;
    calc(i,array,n,res);
  }
  int ans=1;
  for(i=0;i<n;i++){
    ans=MAX(ans,res[i]);
  }
  printf("%d\n",ans);
  free(array);
  return;
}

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