結果

問題 No.497 入れ子の箱
ユーザー fiordfiord
提出日時 2017-03-28 18:33:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 5,000 ms
コード長 1,118 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 84,200 KB
実行使用メモリ 6,376 KB
最終ジャッジ日時 2023-09-20 18:33:50
合計ジャッジ時間 4,031 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 63 ms
6,268 KB
testcase_04 AC 73 ms
6,148 KB
testcase_05 AC 73 ms
6,108 KB
testcase_06 AC 73 ms
6,268 KB
testcase_07 AC 73 ms
6,140 KB
testcase_08 AC 74 ms
6,160 KB
testcase_09 AC 74 ms
6,128 KB
testcase_10 AC 75 ms
6,160 KB
testcase_11 AC 73 ms
6,100 KB
testcase_12 AC 80 ms
4,996 KB
testcase_13 AC 80 ms
4,964 KB
testcase_14 AC 81 ms
4,968 KB
testcase_15 AC 81 ms
4,892 KB
testcase_16 AC 81 ms
4,868 KB
testcase_17 AC 80 ms
4,820 KB
testcase_18 AC 70 ms
6,140 KB
testcase_19 AC 70 ms
6,376 KB
testcase_20 AC 70 ms
6,080 KB
testcase_21 AC 70 ms
6,156 KB
testcase_22 AC 70 ms
6,080 KB
testcase_23 AC 56 ms
4,380 KB
testcase_24 AC 57 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 76 ms
5,420 KB
testcase_28 AC 76 ms
5,424 KB
testcase_29 AC 76 ms
5,504 KB
testcase_30 AC 73 ms
4,380 KB
testcase_31 AC 73 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

vector<int> edge[1010];
int rest[1010];
int depth[1010];

bool contain(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;	cin >> n;
	vector<vector<int>> dat(n, vector<int>(3));
	for (int i = 0; i < n; i++) {
		cin >> dat[i][0] >> dat[i][1] >> dat[i][2];
		sort(dat[i].begin(), dat[i].end());
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (contain(dat[i], dat[j])) {
				edge[i].push_back(j);
				rest[j]++;
			}
		}
	}
	queue<int> q;
	for (int i = 0; i < n; i++) {
		if (rest[i] == 0) {
			depth[i] = 1;
			q.push(i);
		}
	}
	while (!q.empty()) {
		int cur = q.front();	q.pop();
		for (int i = 0; i < edge[cur].size(); i++){
			int to = edge[cur][i];
			depth[to] = max(depth[to], depth[cur] + 1);
			rest[to]--;
			if (rest[to] == 0)	q.push(to);
		}
	}
	int ret = 0;
	for (int i = 0; i < n; i++)	ret = max(ret, depth[i]);
	cout << ret << endl;
	return 0;
}
0