結果

問題 No.497 入れ子の箱
ユーザー masamasa
提出日時 2017-04-18 12:12:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 1,207 bytes
コンパイル時間 1,284 ms
コンパイル使用メモリ 96,168 KB
実行使用メモリ 27,084 KB
最終ジャッジ日時 2023-09-26 13:14:02
合計ジャッジ時間 6,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 143 ms
26,888 KB
testcase_04 AC 154 ms
26,808 KB
testcase_05 AC 155 ms
26,868 KB
testcase_06 AC 155 ms
26,868 KB
testcase_07 AC 154 ms
26,812 KB
testcase_08 AC 155 ms
26,896 KB
testcase_09 AC 155 ms
27,084 KB
testcase_10 AC 154 ms
26,864 KB
testcase_11 AC 155 ms
26,812 KB
testcase_12 AC 118 ms
15,372 KB
testcase_13 AC 117 ms
14,932 KB
testcase_14 AC 117 ms
14,980 KB
testcase_15 AC 119 ms
15,536 KB
testcase_16 AC 119 ms
15,552 KB
testcase_17 AC 120 ms
14,984 KB
testcase_18 AC 152 ms
26,848 KB
testcase_19 AC 151 ms
26,896 KB
testcase_20 AC 150 ms
26,852 KB
testcase_21 AC 151 ms
26,824 KB
testcase_22 AC 151 ms
26,820 KB
testcase_23 AC 54 ms
4,384 KB
testcase_24 AC 55 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 131 ms
19,800 KB
testcase_28 AC 132 ms
19,820 KB
testcase_29 AC 130 ms
19,496 KB
testcase_30 AC 71 ms
4,380 KB
testcase_31 AC 71 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using PII = pair<int, int>;

bool is_bigger(vector<int> a, vector<int> b) {
	do {
		if (a[0] > b[0] && a[1] > b[1] && a[2] > b[2]) {
			return true;
		}
	} while (next_permutation(b.begin(), b.end()));

	return false;
}

int main() {
	int n, x, y, z;
	cin >> n;

	vector<vector<int>> cubes(n);
	for (int i = 0; i < n; i++) {
		cin >> x >> y >> z;
		cubes[i] = {x, y, z};
		sort(cubes[i].begin(), cubes[i].end());
	}

	vector<set<int>> connect(n);

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j && is_bigger(cubes[i], cubes[j])) {
				connect[i].insert(j);
			}
		}
	}

	priority_queue<PII, vector<PII>, greater<PII>> que;
	for (int i = 0; i < n; i++) {
		que.push(make_pair(connect[i].size(), i));
	}


	vector<int> memo(n, 0);
	while (!que.empty()) {
		auto p = que.top();
		que.pop();
		int x = p.second;
		int maxi = memo[x];
		for (auto e : connect[x]) {
			maxi = max(maxi, memo[e]);
		}
		memo[x] = maxi + 1;
	}

	cout << *max_element(memo.begin(), memo.end()) << endl;
	return 0;
}
0