結果

問題 No.497 入れ子の箱
ユーザー どららどらら
提出日時 2017-03-25 02:58:55
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 2,524 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 179,832 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2023-09-20 07:30:44
合計ジャッジ時間 3,916 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 18 ms
8,968 KB
testcase_04 AC 18 ms
8,948 KB
testcase_05 AC 18 ms
9,020 KB
testcase_06 AC 19 ms
9,048 KB
testcase_07 AC 23 ms
9,060 KB
testcase_08 AC 22 ms
9,216 KB
testcase_09 AC 23 ms
8,908 KB
testcase_10 AC 23 ms
8,984 KB
testcase_11 AC 23 ms
9,156 KB
testcase_12 AC 25 ms
6,436 KB
testcase_13 AC 25 ms
6,560 KB
testcase_14 AC 24 ms
6,288 KB
testcase_15 AC 25 ms
6,468 KB
testcase_16 AC 24 ms
6,420 KB
testcase_17 AC 25 ms
6,380 KB
testcase_18 AC 15 ms
8,768 KB
testcase_19 AC 15 ms
8,716 KB
testcase_20 AC 15 ms
8,828 KB
testcase_21 AC 15 ms
8,708 KB
testcase_22 AC 15 ms
8,820 KB
testcase_23 AC 5 ms
4,380 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 21 ms
7,492 KB
testcase_28 AC 21 ms
7,376 KB
testcase_29 AC 21 ms
7,312 KB
testcase_30 AC 11 ms
4,380 KB
testcase_31 AC 12 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

struct ST{
  int X, Y, Z;
};

template<int MAX_V>
class SCC {
  vector<int> G[MAX_V];
  vector<int> rG[MAX_V];
  vector<int> vs;
  bool used[MAX_V];

  int V;
  vector<int> cmp;

  void dfs(int v){
    used[v] = true;
    for(int i=0; i<G[v].size(); i++)
      if(!used[G[v][i]]) dfs(G[v][i]);
    vs.push_back(v);
  }
  
  void rdfs(int v, int k){
    used[v] = true;
    cmp[v] = k;
    for(int i=0; i<rG[v].size(); i++)
      if(!used[rG[v][i]]) rdfs(rG[v][i], k);
  }
public:
  SCC(int V):V(V),cmp(V){}

  int size(){ return V; }

  vector<int> get_edge(int from){ return G[from]; }
  vector<int> get_cmp(){ return cmp; }
  
  void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
  }
  
  int calc(){
    for(int i=0; i<MAX_V; i++) used[i] = 0;
    vs.clear();
    for(int v=0; v<V; v++)
      if(!used[v]) dfs(v);
    for(int i=0; i<MAX_V; i++) used[i] = 0;
    int k = 0;
    for(int i=vs.size()-1; i>=0; i--)
      if(!used[vs[i]]) rdfs(vs[i], k++);
    return k;
  }

  vector<int> depth(){
    vector<pair<int,int>> order;
    vector<int> dp(V, 1);

    calc();

    for(int i=0; i<V; i++){
      order.push_back(make_pair(cmp[i],i));
    }
    sort(order.begin(), order.end());

    for(int i=0; i<V; i++){
      int node = order[i].second;
      rep(j,G[node].size()){
        dp[G[node][j]] = max(dp[G[node][j]], dp[node]+1);
      }
    }
    return dp;
  }
};


bool can_in(const ST& a, const ST& b){
  if(a.X < b.X && a.Y < b.Y && a.Z < b.Z) return true;
  if(a.X < b.X && a.Y < b.Z && a.Z < b.Y) return true;
  if(a.X < b.Y && a.Y < b.X && a.Z < b.Z) return true;
  if(a.X < b.Y && a.Y < b.Z && a.Z < b.X) return true;
  if(a.X < b.Z && a.Y < b.X && a.Z < b.Y) return true;
  if(a.X < b.Z && a.Y < b.Y && a.Z < b.X) return true;
  return false;
}


int main(){
  int N;
  cin >> N;
  vector<ST> v;
  rep(i,N){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    v.push_back((ST){X,Y,Z});
  }

  SCC<1005> scc(N);
  rep(i,N){
    rep(j,N){
      if(i == j) continue;
      if(can_in(v[i], v[j])){
        scc.add_edge(i,j);
      }
    }
  }
  vector<int> dp = scc.depth();

  int ret = 0;
  rep(i,dp.size()){
    ret = max(ret, dp[i]);
  }
  cout << ret << endl;
  
  return 0;
}
0