結果
問題 | No.497 入れ子の箱 |
ユーザー |
![]() |
提出日時 | 2017-03-24 23:30:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 5,000 ms |
コード長 | 2,301 bytes |
コンパイル時間 | 1,888 ms |
コンパイル使用メモリ | 181,800 KB |
実行使用メモリ | 9,088 KB |
最終ジャッジ日時 | 2024-07-06 00:13:06 |
合計ジャッジ時間 | 3,318 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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;};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;}