結果

問題 No.497 入れ子の箱
ユーザー outlineoutline
提出日時 2021-02-18 14:52:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 5,000 ms
コード長 2,295 bytes
コンパイル時間 1,540 ms
コンパイル使用メモリ 143,016 KB
実行使用メモリ 6,340 KB
最終ジャッジ日時 2023-10-12 23:13:40
合計ジャッジ時間 3,396 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 15 ms
5,984 KB
testcase_04 AC 15 ms
6,116 KB
testcase_05 AC 15 ms
6,340 KB
testcase_06 AC 15 ms
5,944 KB
testcase_07 AC 22 ms
6,188 KB
testcase_08 AC 21 ms
6,092 KB
testcase_09 AC 22 ms
6,196 KB
testcase_10 AC 22 ms
5,992 KB
testcase_11 AC 22 ms
5,896 KB
testcase_12 AC 27 ms
4,860 KB
testcase_13 AC 27 ms
4,912 KB
testcase_14 AC 27 ms
4,820 KB
testcase_15 AC 27 ms
4,924 KB
testcase_16 AC 27 ms
4,924 KB
testcase_17 AC 27 ms
4,892 KB
testcase_18 AC 12 ms
6,088 KB
testcase_19 AC 12 ms
6,212 KB
testcase_20 AC 12 ms
6,160 KB
testcase_21 AC 12 ms
6,204 KB
testcase_22 AC 12 ms
6,160 KB
testcase_23 AC 5 ms
4,352 KB
testcase_24 AC 6 ms
4,352 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 1 ms
4,352 KB
testcase_27 AC 22 ms
5,456 KB
testcase_28 AC 22 ms
5,404 KB
testcase_29 AC 23 ms
5,432 KB
testcase_30 AC 13 ms
4,348 KB
testcase_31 AC 13 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<vector<int>> X(N, vector<int>(3));
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> X[i][j];
        }
    }

    vector<vector<int>> g(N);
    vector<int> indeg(N);
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < N; ++j){
            if(j != i){
                bool directed = false;
                for(int k = 0; k < 3; ++k){
                    if(X[i][0] < X[j][k]){
                        int pk = (k - 1 + 3) % 3, nk = (k + 1) % 3;
                        if((X[i][1] < X[j][pk] && X[i][2] < X[j][nk]) || (X[i][1] < X[j][nk] && X[i][2] < X[j][pk])){
                            directed = true;
                        }
                    }
                }
                if(directed){
                    g[i].emplace_back(j);
                    indeg[j] += 1;
                }
            }
        }
    }

    vector<int> dp(N, 1);
    queue<int> que;
    for(int i = 0; i < N; ++i){
        if(indeg[i] == 0)   que.emplace(i);
    }
    while(!que.empty()){
        int from = que.front();
        que.pop();
        for(int to : g[from]){
            chmax(dp[to], dp[from] + 1);
            if(--indeg[to] == 0)    que.emplace(to);
        }
    }

    cout << *max_element(begin(dp), end(dp)) << endl;

    return 0;
}
0