結果
問題 | No.274 The Wall |
ユーザー |
![]() |
提出日時 | 2019-06-07 20:46:15 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 269 ms / 2,000 ms |
コード長 | 2,043 bytes |
コンパイル時間 | 1,904 ms |
コンパイル使用メモリ | 175,348 KB |
実行使用メモリ | 140,336 KB |
最終ジャッジ日時 | 2025-03-17 19:02:33 |
合計ジャッジ時間 | 3,495 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include<bits/stdc++.h> #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vll; const ll INF = INT_MAX; const ll MOD = 20171211; struct Edge{ ll dst; Edge(ll t):dst(t){} }; using Edges=vector<Edge>; using Graph=vector<Edges>; vector<vector<int>> SCC(const Graph& g,vector<int> &I) { ll n=g.size(); vector<vector<int>> scc; vector<int> S, B; I.assign(n,0); function<void(int)> dfs = [&](int u) { B.push_back(I[u] = S.size()); S.push_back(u); for(Edge e: g[u]) { int v=e.dst; if (!I[v]) dfs(v); else while (I[v] < B.back()) B.pop_back(); } if (I[u] == B.back()) { scc.push_back({}); B.pop_back(); for (; I[u] < (int)S.size(); S.pop_back()) { scc.back().push_back(S.back()); I[S.back()] = n + scc.size(); } } }; for(int u=0;u<n;u++)if (!I[u]) dfs(u); for(int u=0;u<n;u++)I[u] -= n+1; return scc; } signed main(){ cin.tie(0); ios::sync_with_stdio(false); ll N,M;cin>>N>>M; vll L(N),R(N); for(ll i=0;i<N;i++){ cin>>L[i]>>R[i]; } Graph G(2*N); for(ll i=0;i<N;i++){ for(ll j=i+1;j<N;j++){ if(L[i]<=R[j]&&L[j]<=R[i])G[i].emplace_back(N+j),G[N+j].emplace_back(i); if(L[i]<=(M-1-L[j])&&(M-1-R[j])<=R[i])G[i].emplace_back(j),G[j].emplace_back(i); if((M-1-R[i])<=R[j]&&L[j]<=(M-1-L[i]))G[N+i].emplace_back(N+j),G[N+j].emplace_back(N+i); if((M-1-R[i])<=(M-1-L[j])&&(M-1-R[j])<=(M-1-L[i]))G[N+1].emplace_back(j),G[j].emplace_back(N+i); } } vector<int> idx; vector<vector<int>> scc=SCC(G,idx); /* debug(scc.size()); debugArray(idx,N*2); */ bool isok=true; for(ll i=0;i<N;i++){ isok &= idx[i]!=idx[N+i]; } cout<<(isok? "YES":"NO")<<endl; return 0; }