結果
問題 | No.274 The Wall |
ユーザー |
![]() |
提出日時 | 2020-08-26 18:43:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 598 ms / 2,000 ms |
コード長 | 4,319 bytes |
コンパイル時間 | 5,658 ms |
コンパイル使用メモリ | 249,820 KB |
最終ジャッジ日時 | 2025-01-13 15:02:29 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 22 |
ソースコード
#pragma GCC optimize("Ofast")#include <bits/stdc++.h>#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/tree_policy.hpp>using namespace std;using namespace __gnu_pbds;using ll = long long;using ull = unsigned long long;using pii = pair<int, int>;using pll = pair<long long, long long>;#define rep(i, n) for(int i = 0; i < (n); ++i)#define all(x) (x).begin(),(x).end()constexpr char ln = '\n';constexpr long long MOD = 1000000007;//constexpr long long MOD = 998244353;template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }inline int popcount(int x) {return __builtin_popcount(x);}inline int popcount(long long x) {return __builtin_popcountll(x);}void print() { cout << "\n"; }template<class T, class... Args>void print(const T &x, const Args &... args) {cout << x << " ";print(args...);}///////////////////////////////////////////////////////////////////////////////////////////////////////////////struct StronglyConnectedComponent {//T:強連結成分をトポロジカルソートしたグラフ C:強連結成分の内訳vector<vector<int>> G,R,T,C;vector<int> vs,used,blg;StronglyConnectedComponent() {}StronglyConnectedComponent(int N) : G(N), R(N), used(N), blg(N) {}void add_edge(int u,int v) {G[u].emplace_back(v);R[v].emplace_back(u);}void dfs(int v){used[v] = 1;for(int u:G[v]) {if(!used[u]) dfs(u);}vs.emplace_back(v);}void rdfs(int v, int k) {used[v] = 1;blg[v] = k;C[k].emplace_back(v);for(int u:R[v]) {if(!used[u]) rdfs(u,k);}}int build() {int N = G.size();for(int v = 0; v < N; v++) {if(!used[v]) dfs(v);}fill(used.begin(),used.end(),0);int k = 0;for(int i = N-1; i >= 0; i--) {if(!used[vs[i]]) {T.emplace_back();C.emplace_back();rdfs(vs[i], k++);}}for(int v = 0; v < N; v++) {for(int u:G[v]) {if(blg[v] != blg[u]) T[blg[v]].emplace_back(blg[u]);}}for(int i = 0; i < k; i++) {sort(T[i].begin(),T[i].end());T[i].erase(unique(T[i].begin(),T[i].end()),T[i].end());}return k;}int operator[](int k) const{return blg[k];}};struct TwoSat {int N;StronglyConnectedComponent scc;TwoSat(int N) : N(N), scc(N*2) {}int negate(int v) {return (N+v)%(N*2);}void add_if(int u, int v) {// u -> v <=> !v -> !uscc.add_edge(u,v);scc.add_edge(negate(v),negate(u));}void add_or(int u, int v) {// u or v <=> !u -> vadd_if(negate(u),v);}void add_nand(int u, int v) {// u nand v <=> u -> !vadd_if(u,negate(v));}void set_true(int v) {// v <=> !v -> vscc.add_edge(negate(v),v);}void set_false(int v) {// !v <=> v -> !vscc.add_edge(v,negate(v));}vector<int> build() {scc.build();vector<int> ret(N);for (int i = 0; i < N; ++i) {if(scc[i]==scc[N+i]) return {};ret[i] = scc[i] > scc[N+i];}return ret;}};int main() {ios::sync_with_stdio(false); cin.tie(nullptr);int N,M; cin >> N >> M;vector<int> L(N),R(N);rep(i,N) cin >> L[i] >> R[i];auto check=[](int l1, int r1, int l2, int r2) {if (l1 > l2) {swap(l1,l2);swap(r1,r2);}if (r1 >= l2) return false;return true;};TwoSat T(N);rep(i,N) {rep(j,i) {if (!check(L[i],R[i],L[j],R[j])) T.add_nand(i,j);if (!check(L[i],R[i],M-1-R[j],M-1-L[j])) T.add_nand(i,j+N);if (!check(M-1-R[i],M-1-L[i],L[j],R[j])) T.add_nand(i+N,j);if (!check(M-1-R[i],M-1-L[i],M-1-R[j],M-1-L[j])) T.add_nand(i+N,j+N);}}auto ans = T.build();cout << (ans.empty() ? "NO" : "YES") << ln;}