結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 2017-03-25 02:58:55 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 5,000 ms |
コード長 | 2,524 bytes |
コンパイル時間 | 2,024 ms |
コンパイル使用メモリ | 183,696 KB |
実行使用メモリ | 9,216 KB |
最終ジャッジ日時 | 2024-07-06 03:26:20 |
合計ジャッジ時間 | 2,858 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 29 |
ソースコード
#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;}