結果

問題 No.497 入れ子の箱
ユーザー startcppstartcpp
提出日時 2017-03-24 23:05:58
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,337 bytes
コンパイル時間 660 ms
コンパイル使用メモリ 66,004 KB
実行使用メモリ 10,248 KB
最終ジャッジ日時 2023-09-20 02:57:31
合計ジャッジ時間 7,184 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//直方体iの中に直方体jが入るとき, i->jと辺をはったグラフGを考える. GはDAGになる.
//直方体iの中に直方体jが入るかどうかは, 直方体iの外側に依存しないので, G上の最長パスが答えになる。
//これは, dfs(v)…頂点vから辿れる辺の最大個数, とおけばO(N + E)で求めることができる。(Eは辺の個数なので, 最大N^2個くらい)
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> et[1000];
int dp[1000];

int dfs(int v) {
	int ret = 0;
	for (int i = 0; i < et[v].size(); i++) {
		ret = max(ret, dfs(et[v][i]) + 1);
	}
	return ret;
}

int main() {
	int n;
	int x[1000], y[1000], z[1000];
	int i, j, k;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i];
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (i == j) continue;
			
			//直方体iの中に直方体jが入る場合に, i->jと辺をはる
			int a[3] = {x[i], y[i], z[i]};
			int b[3] = {x[j], y[j], z[j]};
			sort(a, a + 3);
			sort(b, b + 3);
			for (k = 0; k < 3; k++) {
				if (a[k] <= b[k]) {
					break;
				}
			}
			if (k == 3) {
				et[i].push_back(j);
			}
		}
	}
	for (i = 0; i < n; i++) dp[i] = -1;
	
	int ans = 0;
	for (i = 0; i < n; i++) ans = max(ans, dfs(i) + 1);
	cout << ans << endl;
	return 0;
}
0