結果

問題 No.497 入れ子の箱
ユーザー masa
提出日時 2017-04-18 12:12:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 141 ms / 5,000 ms
コード長 1,207 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 96,332 KB
実行使用メモリ 27,008 KB
最終ジャッジ日時 2024-07-19 07:36:30
合計ジャッジ時間 5,377 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0