結果

問題 No.497 入れ子の箱
ユーザー confconf
提出日時 2017-03-17 03:19:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 5,000 ms
コード長 1,915 bytes
コンパイル時間 978 ms
コンパイル使用メモリ 88,768 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-09-20 05:18:33
合計ジャッジ時間 2,729 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 17 ms
8,128 KB
testcase_04 AC 17 ms
8,068 KB
testcase_05 AC 17 ms
8,156 KB
testcase_06 AC 17 ms
8,048 KB
testcase_07 AC 22 ms
8,348 KB
testcase_08 AC 22 ms
8,116 KB
testcase_09 AC 21 ms
8,184 KB
testcase_10 AC 22 ms
8,084 KB
testcase_11 AC 22 ms
8,064 KB
testcase_12 AC 25 ms
5,868 KB
testcase_13 AC 25 ms
5,808 KB
testcase_14 AC 25 ms
5,772 KB
testcase_15 AC 26 ms
5,892 KB
testcase_16 AC 25 ms
5,876 KB
testcase_17 AC 25 ms
5,824 KB
testcase_18 AC 14 ms
8,344 KB
testcase_19 AC 15 ms
8,308 KB
testcase_20 AC 14 ms
8,044 KB
testcase_21 AC 14 ms
8,184 KB
testcase_22 AC 15 ms
8,040 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 7 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 22 ms
6,776 KB
testcase_28 AC 22 ms
6,792 KB
testcase_29 AC 22 ms
6,792 KB
testcase_30 AC 13 ms
4,376 KB
testcase_31 AC 13 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <assert.h> 
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
typedef tuple<int,int,int> T;
typedef vector<vector<int>> Graph;

class Topological_Sort{
    Graph G;
    public:vector<int> order;
    vector<bool> visited;
    void dfs(int v){
        if(visited[v]) return;
        visited[v]=true;
        for(auto &to:G[v]){
            dfs(to);
        }
        order.push_back(v);
        return;
    };
    Topological_Sort(Graph &g) : G(g) {
        visited = vector<bool>(G.size());
        for(int i=0;i<G.size();i++) dfs(i);
        reverse(order.begin(), order.end());
    };
};

bool putin(T &A, T &B){//AがBに入るか
    int Ax,Ay,Az,Bx,By,Bz;
    tie(Ax,Ay,Az)=A;
    tie(Bx,By,Bz)=B;
    if(Ax<Bx&&Ay<By&&Az<Bz) return true;
    if(Ax<Bx&&Ay<Bz&&Az<By) return true;
    if(Ax<By&&Ay<Bx&&Az<Bz) return true;
    if(Ax<By&&Ay<Bz&&Az<Bx) return true;
    if(Ax<Bz&&Ay<Bx&&Az<By) return true;
    if(Ax<Bz&&Ay<By&&Az<Bx) return true;
    return false;
}

int main(){
    int N;
    cin>>N;
    assert(1<=N&&N<=1000);
    vector<T> B;
    for(int i=0;i<N;i++){
        int X,Y,Z;
        cin>>X>>Y>>Z;
        assert(1<=X&&X<100000000);
        assert(1<=Y&&Y<100000000);
        assert(1<=Z&&Z<100000000);
        B.emplace_back(X,Y,Z);
    }
    Graph G(N);
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(putin(B[i],B[j])) G[i].push_back(j);
        }
    }
    Topological_Sort TS(G);
    vector<T> B2;
    for(auto o:TS.order) B2.push_back(B[o]);
    int DP[N];
    fill(DP,DP+N,0);
    for(int i=N-1;i>=0;i--){
        int maximum = 0;
        for(int j=i+1;j<N;j++){
            if(putin(B2[i],B2[j])){
                maximum=max(maximum,DP[j]);
            }
        }
        DP[i]=maximum+1;
    }
    int ans = 0;
    for(int i=0;i<N;i++){
        ans=max(ans,DP[i]);
    }
    cout<<ans<<endl;

    return 0;
}
0