結果

問題 No.497 入れ子の箱
ユーザー femtofemto
提出日時 2017-03-24 23:16:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 1,297 bytes
コンパイル時間 1,908 ms
コンパイル使用メモリ 176,956 KB
実行使用メモリ 6,276 KB
最終ジャッジ日時 2023-09-20 03:39:34
合計ジャッジ時間 4,450 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 29 ms
5,876 KB
testcase_04 AC 46 ms
6,076 KB
testcase_05 AC 47 ms
6,248 KB
testcase_06 AC 48 ms
5,976 KB
testcase_07 AC 47 ms
6,140 KB
testcase_08 AC 47 ms
6,124 KB
testcase_09 AC 47 ms
6,080 KB
testcase_10 AC 47 ms
5,604 KB
testcase_11 AC 47 ms
6,132 KB
testcase_12 AC 47 ms
4,840 KB
testcase_13 AC 47 ms
4,840 KB
testcase_14 AC 47 ms
4,796 KB
testcase_15 AC 46 ms
4,988 KB
testcase_16 AC 47 ms
5,068 KB
testcase_17 AC 47 ms
4,776 KB
testcase_18 AC 44 ms
6,076 KB
testcase_19 AC 44 ms
6,276 KB
testcase_20 AC 44 ms
6,044 KB
testcase_21 AC 44 ms
6,084 KB
testcase_22 AC 44 ms
6,200 KB
testcase_23 AC 20 ms
4,376 KB
testcase_24 AC 21 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 47 ms
5,340 KB
testcase_28 AC 46 ms
5,532 KB
testcase_29 AC 45 ms
5,276 KB
testcase_30 AC 31 ms
4,376 KB
testcase_31 AC 30 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

vector<int> tsort(const vector<vector<int> > &g) {
	int n = g.size(), k = 0;
	vector<int> ord(n), in(n);
	for(auto &es : g) for(auto &e : es) in[e]++;
	queue<int> q;
	for(int i = 0; i < n; ++i) if(in[i] == 0) q.push(i);
	while(q.size()) {
		int v = q.front(); q.pop(); ord[k++] = v;
		for(auto &e : g[v]) if(--in[e] == 0) q.push(e);
	}
	return *max_element(in.begin(), in.end()) == 0 ? ord : vector<int>();
}

int X[1000];
int Y[1000];
int Z[1000];

bool in(int x1, int y1, int z1, int x2, int y2, int z2) {
	int a[3] = { x1, y1, z1 };
	int b[3] = { x2, y2, z2 };
	sort(a, a + 3);
	sort(b, b + 3);
	for(int i = 0; i < 3; i++) {
		if(a[i] >= b[i]) return false;
	}
	return true;
}

int dist[1000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	vector<vector<int>> G(N);
	for(int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> Z[i];
	}

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < N; j++) {
			if(i == j) continue;
			if(in(X[i], Y[i], Z[i], X[j], Y[j], Z[j])) {
				G[i].push_back(j);
			}
		}
	}

	auto res = tsort(G);
	for(int i = 0; i < N; i++) {
		int v = res[i];
		for(auto u : G[v]) {
			dist[u] = max(dist[u], dist[v] + 1);
		}
	}

	cout << *max_element(dist, dist + N) + 1 << endl;
}
0