結果

問題 No.497 入れ子の箱
コンテスト
ユーザー myanta
提出日時 2017-06-30 10:07:21
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,118 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 500 ms
コンパイル使用メモリ 69,444 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-20 13:53:15
合計ジャッジ時間 1,402 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using ll=long long;


class box_t
{
	int x, y, z;
public:
	box_t(int x, int y, int z)
	{
		if(x>y) swap(x, y);
		if(x>z) swap(x, z);
		if(y>z) swap(y, z);
		this->x=x;
		this->y=y;
		this->z=z;
	}
	bool operator<(const box_t&rhs) const
	{
		if(x!=rhs.x) return x<rhs.x;
		if(y!=rhs.y) return y<rhs.y;
		return z<rhs.z;
	}
	bool greater(box_t& rhs)
	{
		return (x>rhs.x && y>rhs.y && z>rhs.z);
	}
	void print(void)
	{
		printf("%d %d %d\n", x, y, z);
	}
};

int solve(vector<box_t>&b)
{
	int n=b.size();
	vector<int> dp(n, 1);

	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(b[i].greater(b[j]))
			{
				dp[i]=max(dp[i], dp[j]+1);
			}
		}
	}

	int ret=dp[0];
	for(int i=1;i<n;i++)
	{
		ret=max(ret, dp[i]);
	}
	return ret;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vector<box_t> b;
		for(int i=0;i<n;i++)
		{
			int x, y, z;
			scanf("%d%d%d", &x, &y, &z);
			b.push_back(box_t(x, y, z));
		}
		sort(b.begin(), b.end());
		printf("%d\n", solve(b));
	}

	return 0;
}
0