結果

問題 No.497 入れ子の箱
ユーザー ふっぴーふっぴー
提出日時 2017-03-25 00:01:10
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,448 bytes
コンパイル時間 806 ms
コンパイル使用メモリ 30,904 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-20 06:23:34
合計ジャッジ時間 2,295 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>

void swap3(int *a,int *b,int *c);
void swap2(int *a,int *b);
void Qsort(int x[], int left, int right, int y[], int z[]);
void swap(int x[],int i,int j);
int max(int a,int b);

int main(void){
	int n;
	scanf("%d",&n);
	int x[n],y[n],z[n];
	int a,b,c;
	int i,j;
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		swap3(&a,&b,&c);
		x[i]=a;y[i]=b;z[i]=c;
	}
	int dp[n];
	for(i=0;i<n;i++){
		dp[i]=1;
	}
	Qsort(x,0,n-1,y,z);
	for(i=0;i<n;i++){
		for(j=0;j<i;j++){
			if(x[i]>x[j] && y[i]>y[j] && z[i]>z[j]){
				dp[i]=max(dp[j]+1,dp[i]);
			}
		}
	}
	int ans=1;
	for(i=0;i<n;i++){
		ans=max(ans,dp[i]);
	}
	printf("%d\n",ans);
	return 0;
}

void swap2(int *a,int *b){
	int k;
	if(*a<=*b){
		k=*a;
		*a=*b;
		*b=k;
	}
}

void swap3(int *a,int *b,int *c){
	if(*a<*b){
		swap2(a,b);
	}
	if(*a<*c){
		swap2(a,c);
	}
	if(*b<*c){
		swap2(b,c);
	}
}

	
void Qsort(int x[], int left, int right,int y[],int z[]){
	int i,j;
	int pivot;
	i=left;
	j=right;
	pivot=x[(left+right)/2];
	while(1){
		while(x[i]<pivot)
			i++;
		while(pivot<x[j])
			j--;
		if(i>=j)
			break;
		swap(x,i,j);
		swap(y,i,j);
		swap(z,i,j);
		i++;
		j--;
	}
	if(left<i-1)
		Qsort(x,left,i-1,y,z);
	if(j+1<right)
		Qsort(x,j+1,right,y,z);
}

void swap(int x[],int i,int j){
	int temp;
	temp=x[i];
	x[i]=x[j];
	x[j]=temp;
}

int max(int a,int b){
	if(a>=b){
		return a;
	}else{
		return b;
	}
}
0