結果

問題 No.497 入れ子の箱
ユーザー どららどらら
提出日時 2017-03-24 23:30:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 2,301 bytes
コンパイル時間 1,837 ms
コンパイル使用メモリ 179,104 KB
実行使用メモリ 9,132 KB
最終ジャッジ日時 2023-09-20 03:56:23
合計ジャッジ時間 3,950 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 18 ms
8,992 KB
testcase_04 AC 18 ms
9,132 KB
testcase_05 AC 18 ms
8,952 KB
testcase_06 AC 19 ms
9,012 KB
testcase_07 AC 23 ms
8,976 KB
testcase_08 AC 22 ms
8,940 KB
testcase_09 AC 23 ms
9,080 KB
testcase_10 AC 23 ms
9,004 KB
testcase_11 AC 23 ms
8,996 KB
testcase_12 AC 25 ms
6,384 KB
testcase_13 AC 25 ms
6,360 KB
testcase_14 AC 25 ms
6,384 KB
testcase_15 AC 25 ms
6,388 KB
testcase_16 AC 25 ms
6,364 KB
testcase_17 AC 25 ms
6,376 KB
testcase_18 AC 15 ms
8,796 KB
testcase_19 AC 15 ms
8,732 KB
testcase_20 AC 15 ms
8,748 KB
testcase_21 AC 15 ms
8,712 KB
testcase_22 AC 15 ms
8,716 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 6 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 21 ms
7,404 KB
testcase_28 AC 22 ms
7,468 KB
testcase_29 AC 21 ms
7,532 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 11 ms
4,376 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;
};

class SCC {
public:
  static const int MAX_V = 1005;
  vector<int> G[MAX_V];
  vector<int> rG[MAX_V];
  vector<int> vs;
  bool used[MAX_V];

  int V;
  int cmp[MAX_V];

  void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
  }
private:  
  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:
  int calc(){
    for(int i=0; i<sizeof(used); i++) used[i] = 0;
    vs.clear();
    for(int v=0; v<V; v++)
      if(!used[v]) dfs(v);
    for(int i=0; i<sizeof(used); 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;
  }
};


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 scc;
  scc.V = N;
  rep(i,N){
    rep(j,N){
      if(i == j) continue;
      if(can_in(v[i], v[j])){
        scc.add_edge(i,j);
      }
    }
  }
  scc.calc();

  vector<pair<int,int>> order;
  rep(i,N){
    order.push_back(make_pair(scc.cmp[i],i));
  }
  sort(ALLOF(order));

  vector<int> dp(N, 1);
  
  rep(i,N){
    int node = order[i].second;
    rep(j,scc.G[node].size()){
      dp[scc.G[node][j]] = max(dp[scc.G[node][j]], dp[node]+1);
    }
  }

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