結果
問題 |
No.274 The Wall
|
ユーザー |
![]() |
提出日時 | 2021-03-12 00:11:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 508 ms / 2,000 ms |
コード長 | 2,889 bytes |
コンパイル時間 | 2,770 ms |
コンパイル使用メモリ | 215,964 KB |
実行使用メモリ | 194,944 KB |
最終ジャッジ日時 | 2025-03-17 19:09:32 |
合計ジャッジ時間 | 5,291 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; // #include <atcoder/all> // using namespace atcoder; struct StronglyConnectedComponents { int n; vector<vector<int>> G, rG; vector<int> order, component; vector<bool> used; void dfs(int v) { used[v] = 1; for (auto nv : G[v]) { if (!used[nv]) dfs(nv); } order.push_back(v); } void rdfs(int v, int k) { component[v] = k; for (auto nv : rG[v]) { if (component[nv] < 0) rdfs(nv, k); } } StronglyConnectedComponents(vector<vector<int>> &_G) { n = _G.size(); G = _G; rG.resize(n); component.assign(n, -1); used.resize(n); for (int v = 0; v < n; v++) { for (auto nv : G[v]) rG[nv].push_back(v); } for (int v = 0; v < n; v++) if (!used[v]) dfs(v); int k = 0; reverse(order.begin(), order.end()); for (auto v : order) if (component[v] == -1) rdfs(v, k), k++; } bool is_same(int u, int v) { return component[u] == component[v]; } vector<vector<int>> rebuild() { int N = *max_element(component.begin(), component.end()) + 1; vector<vector<int>> rebuildedG(N); set<pair<int, int>> connected; for (int v = 0; v < N; v++) { for (auto nv : G[v]) { if (component[v] != component[nv] and !connected.count(pair(v, nv))) { connected.insert(pair(v, nv)); rebuildedG[component[v]].push_back(component[nv]); } } } return rebuildedG; } }; #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) using ll = long long; template<class t> using vc=vector<t>; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); int n,m; cin>>n>>m; vc<int> l(n), r(n); rep(i,n) cin>>l[i]>>r[i]; vc<vc<int>> G(2*n); rep(i,n){ irep(j,i+1,n){ int l1=l[i], r1=r[i], l2=l[j], r2=r[j]; int L1=m-r1-1, R1=m-l1-1, L2=m-r2-1, R2=m-l2-1; if(l1<=l2 and l2<=r1 or l1<=r2 and r2<=r1 or l2<=l1 and l1<=r2){ // A∨B <=> ¬A=>B∧¬B=>A G[i+n].push_back(j); G[j+n].push_back(i); } if(l1<=L2 and L2<=r1 or l1<=R2 and R2<=r1 or L2<=l1 and l1<=R2){ // A∨¬B <=> ¬A=>¬B∧B=>A G[i+n].push_back(j+n); G[j].push_back(i); } if(L1<=l2 and l2<=R1 or L1<=r2 and r2<=R1 or l2<=L1 and L1<=r2){ // ¬A∨B <=> A=>B∧¬B=>¬A G[i].push_back(j); G[j+n].push_back(i+n); } if(L1<=L2 and L2<=R1 or L1<=R2 and R2<=R1 or L2<=L1 and L1<=R2){ // ¬A∨¬B <=> A=>¬B∧B=>¬A G[i].push_back(j+n); G[j].push_back(i+n); } } } auto scc = StronglyConnectedComponents(G); rep(i,n){ if(scc.is_same(i,i+n)){ cout<<"NO"<<endl; return 0; } } cout<<"YES"<<endl; }