結果

問題 No.497 入れ子の箱
ユーザー myantamyanta
提出日時 2017-06-30 10:07:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 1,118 bytes
コンパイル時間 435 ms
コンパイル使用メモリ 47,148 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-15 06:42:24
合計ジャッジ時間 1,385 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 4 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 5 ms
6,940 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 5 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 AC 5 ms
6,944 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,944 KB
testcase_20 AC 3 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 2 ms
6,944 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 4 ms
6,944 KB
testcase_28 AC 5 ms
6,944 KB
testcase_29 AC 4 ms
6,940 KB
testcase_30 AC 5 ms
6,944 KB
testcase_31 AC 5 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |                         scanf("%d%d%d", &x, &y, &z);
      |                         ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#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