結果
問題 | No.274 The Wall |
ユーザー | hashiryo |
提出日時 | 2024-09-03 20:42:39 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 567 ms / 2,000 ms |
コード長 | 5,773 bytes |
コンパイル時間 | 2,590 ms |
コンパイル使用メモリ | 220,532 KB |
実行使用メモリ | 253,348 KB |
最終ジャッジ日時 | 2024-09-03 20:42:44 |
合計ジャッジ時間 | 5,070 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 165 ms
86,740 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 567 ms
253,348 KB |
testcase_12 | AC | 7 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 8 ms
6,944 KB |
testcase_16 | AC | 100 ms
53,952 KB |
testcase_17 | AC | 94 ms
50,744 KB |
testcase_18 | AC | 103 ms
55,844 KB |
testcase_19 | AC | 14 ms
6,944 KB |
testcase_20 | AC | 16 ms
6,940 KB |
testcase_21 | AC | 16 ms
6,944 KB |
testcase_22 | AC | 18 ms
6,940 KB |
testcase_23 | AC | 17 ms
6,944 KB |
testcase_24 | AC | 17 ms
6,944 KB |
testcase_25 | AC | 16 ms
6,944 KB |
ソースコード
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> // clang-format off std::ostream&operator<<(std::ostream&os,std::int8_t x){return os<<(int)x;} std::ostream&operator<<(std::ostream&os,std::uint8_t x){return os<<(int)x;} std::ostream&operator<<(std::ostream&os,const __int128_t &u){if(!u)os<<"0";__int128_t tmp=u<0?(os<<"-",-u):u;std::string s;while(tmp)s+='0'+(tmp%10),tmp/=10;return std::reverse(s.begin(),s.end()),os<<s;} std::ostream&operator<<(std::ostream&os,const __uint128_t &u){if(!u)os<<"0";__uint128_t tmp=u;std::string s;while(tmp)s+='0'+(tmp%10),tmp/=10;return std::reverse(s.begin(),s.end()),os<<s;} #define checkpoint() (void(0)) #define debug(...) (void(0)) #define debugArray(x,n) (void(0)) #define debugMatrix(x,h,w) (void(0)) // clang-format on #include <type_traits> #define _LR(name, IT, CT) \ template <class T> struct name { \ using Iterator= typename std::vector<T>::IT; \ Iterator bg, ed; \ Iterator begin() const { return bg; } \ Iterator end() const { return ed; } \ size_t size() const { return std::distance(bg, ed); } \ CT &operator[](int i) const { return bg[i]; } \ } _LR(ListRange, iterator, T); _LR(ConstListRange, const_iterator, const T); #undef _LR template <class T> struct CSRArray { std::vector<T> dat; std::vector<int> p; size_t size() const { return p.size() - 1; } ListRange<T> operator[](int i) { return {dat.begin() + p[i], dat.begin() + p[i + 1]}; } ConstListRange<T> operator[](int i) const { return {dat.cbegin() + p[i], dat.cbegin() + p[i + 1]}; } }; template <template <class> class F, class T> std::enable_if_t<std::disjunction_v<std::is_same<F<T>, ListRange<T>>, std::is_same<F<T>, ConstListRange<T>>, std::is_same<F<T>, CSRArray<T>>>, std::ostream &> operator<<(std::ostream &os, const F<T> &r) { os << '['; for (int _= 0, __= r.size(); _ < __; ++_) os << (_ ? ", " : "") << r[_]; return os << ']'; } struct Edge: std::pair<int, int> { using std::pair<int, int>::pair; Edge &operator--() { return --first, --second, *this; } int to(int v) const { return first ^ second ^ v; } friend std::istream &operator>>(std::istream &is, Edge &e) { return is >> e.first >> e.second, is; } }; struct Graph: std::vector<Edge> { size_t n; Graph(size_t n= 0, size_t m= 0): vector(m), n(n) {} size_t vertex_size() const { return n; } size_t edge_size() const { return size(); } size_t add_vertex() { return n++; } size_t add_edge(int s, int d) { return emplace_back(s, d), size() - 1; } size_t add_edge(Edge e) { return emplace_back(e), size() - 1; } #define _ADJ_FOR(a, b) \ for (auto [u, v]: *this) a; \ for (size_t i= 0; i < n; ++i) p[i + 1]+= p[i]; \ for (int i= size(); i--;) { \ auto [u, v]= (*this)[i]; \ b; \ } #define _ADJ(a, b) \ vector<int> p(n + 1), c(size() << !dir); \ if (!dir) { \ _ADJ_FOR((++p[u], ++p[v]), (c[--p[u]]= a, c[--p[v]]= b)) \ } else if (dir > 0) { \ _ADJ_FOR(++p[u], c[--p[u]]= a) \ } else { \ _ADJ_FOR(++p[v], c[--p[v]]= b) \ } \ return {c, p} CSRArray<int> adjacency_vertex(int dir) const { _ADJ(v, u); } CSRArray<int> adjacency_edge(int dir) const { _ADJ(i, i); } #undef _ADJ #undef _ADJ_FOR }; class StronglyConnectedComponents { std::vector<int> m, q, b; public: StronglyConnectedComponents(const Graph &g) { const int n= g.vertex_size(); m.assign(n, -2), b.resize(n); { auto adj= g.adjacency_vertex(1); std::vector<int> c(adj.p.begin(), adj.p.begin() + n); for (int s= 0, k= n, p; s < n; ++s) if (m[s] == -2) for (m[p= s]= -1; p >= 0;) { if (c[p] == adj.p[p + 1]) b[--k]= p, p= m[p]; else if (int w= adj.dat[c[p]++]; m[w] == -2) m[w]= p, p= w; } } auto adj= g.adjacency_vertex(-1); std::vector<char> z(n); int k= 0, p= 0; q= {0}; for (int s: b) if (!z[s]) { for (z[m[k++]= s]= 1; p < k; ++p) for (int u: adj[m[p]]) if (!z[u]) z[m[k++]= u]= 1; q.push_back(k); } for (int i= q.size() - 1; i--;) while (k > q[i]) b[m[--k]]= i; } size_t size() const { return q.size() - 1; } ConstListRange<int> block(int k) const { return {m.cbegin() + q[k], m.cbegin() + q[k + 1]}; } int operator()(int i) const { return b[i]; } Graph dag(const Graph &g) const { Graph ret(size()); for (auto [s, d]: g) if (b[s] != b[d]) ret.add_edge(b[s], b[d]); return std::sort(ret.begin(), ret.end()), ret.erase(std::unique(ret.begin(), ret.end()), ret.end()), ret; } }; class TwoSatisfiability { int n; Graph g; public: TwoSatisfiability(int n): n(n), g(n + n) {} inline int neg(int x) const { return x >= n ? x - n : x + n; } void add_if(int u, int v) { g.add_edge(u, v), g.add_edge(neg(v), neg(u)); } // u -> v <=> !v -> !u void add_or(int u, int v) { add_if(neg(u), v); } // u or v <=> !u -> v void add_nand(int u, int v) { add_if(u, neg(v)); } // u nand v <=> u -> !v void set_true(int u) { g.add_edge(neg(u), u); } // u <=> !u -> u void set_false(int u) { g.add_edge(u, neg(u)); } // !u <=> u -> !u std::vector<bool> solve() { StronglyConnectedComponents scc(g); std::vector<bool> ret(n); for (int i= 0, l, r; i<n; ret[i++]= l> r) if (l= scc(i), r= scc(neg(i)); l == r) return {}; // no solution return ret; } }; using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(0); int N, M; cin >> N >> M; int L[N], R[N]; for (int i= 0; i < N; ++i) cin >> L[i] >> R[i]; TwoSatisfiability sat(N); for (int i= N; i--;) for (int j= i; j--;) { if (!(R[i] < L[j] || R[j] < L[i])) sat.add_nand(i, j), sat.add_nand(sat.neg(i), sat.neg(j)); if (!(R[i] < M - 1 - R[j] || M - 1 - L[j] < L[i])) sat.add_nand(sat.neg(i), j), sat.add_nand(i, sat.neg(j)); } cout << (sat.solve().empty() ? "NO" : "YES") << '\n'; return 0; }