結果

問題 No.497 入れ子の箱
コンテスト
ユーザー kimiyuki
提出日時 2017-03-27 17:02:16
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,062 ms / 5,000 ms
コード長 1,344 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 643 ms
コンパイル使用メモリ 79,024 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 19:04:13
合計ジャッジ時間 13,363 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     int n; scanf("%d", &n);
      |            ~~~~~^~~~~~~~~~
main.cpp:10:53: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     vector<int> x(n), y(n), z(n); repeat (i,n) scanf("%d%d%d", &x[i], &y[i], &z[i]);
      |                                                ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
int main() {
    int n; scanf("%d", &n);
    vector<int> x(n), y(n), z(n); repeat (i,n) scanf("%d%d%d", &x[i], &y[i], &z[i]);
    vector<vector<int> > g(n);
    vector<int> indegree(n);
    repeat (i,n) {
        array<int, 3> a = {{ x[i], y[i], z[i] }};
        whole(sort, a);
        repeat (j,n) {
            bool found = false;
            do {
                if (a[0] < x[j] and a[1] < y[j] and a[2] < z[j]) {
                    found = true;
                }
            } while (whole(next_permutation, a));
            if (found) {
                g[j].push_back(i);
                indegree[i] += 1;
            }
        }
    }
    vector<int> depth(n, -1);
    function<void (int, int)> dfs = [&](int i, int cur_depth) {
        if (depth[i] < cur_depth) {
            depth[i] = cur_depth;
            for (int j : g[i]) {
                dfs(j, cur_depth + 1);
            }
        }
    };
    repeat (i,n) if (indegree[i] == 0) {
        dfs(i, 0);
    }
    int max_depth = *whole(max_element, depth);
    printf("%d\n", max_depth + 1);
    return 0;
}
0