結果

問題 No.497 入れ子の箱
ユーザー gigimegigime
提出日時 2017-03-24 22:45:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 964 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 179,100 KB
実行使用メモリ 7,680 KB
最終ジャッジ日時 2024-07-05 22:12:43
合計ジャッジ時間 3,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
const int M = 3;
int dp [1001] [1001];
const int INF = 1e9;

int main()
{
	scanf("%d",&N);
	vector< vector<int> > A(N,vector<int>(M));
	FOR(i,0,N){
		FOR(j,0,M){
			scanf("%d",&A [i] [j]);
		}
		sort(ALL(A [i]));
	}
	sort(ALL(A));
	reverse(ALL(A));

	fill(dp [0],dp [N + 1],-INF);
	FOR(i,0,N){
		dp [i + 1] [i] = 1;
	}
	FOR(i,1,N) FOR(j,0,i) if(dp [i] [j] >= 0){
		chmax(dp [i + 1] [j],dp [i] [j]);
		bool ok = true;
		FOR(k,0,M){
			ok &= A [j] [k] > A [i] [k];
		}
		if(ok){
			chmax(dp [i + 1] [i],dp [i] [j] + 1);
		}
	}

	int ans = 0;
	FOR(i,0,N){
		chmax(ans,dp [N] [i]);
	}
	printf("%d\n",ans);

	return 0;
}
0