結果
問題 | No.274 The Wall |
ユーザー | Coki628 |
提出日時 | 2020-09-17 01:07:53 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 376 ms / 2,000 ms |
コード長 | 7,599 bytes |
コンパイル時間 | 2,761 ms |
コンパイル使用メモリ | 221,096 KB |
実行使用メモリ | 192,620 KB |
最終ジャッジ日時 | 2024-06-22 03:51:35 |
合計ジャッジ時間 | 4,456 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 135 ms
69,364 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 376 ms
192,620 KB |
testcase_12 | AC | 6 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 4 ms
6,940 KB |
testcase_15 | AC | 9 ms
6,944 KB |
testcase_16 | AC | 88 ms
40,900 KB |
testcase_17 | AC | 86 ms
39,640 KB |
testcase_18 | AC | 93 ms
42,192 KB |
testcase_19 | AC | 15 ms
6,940 KB |
testcase_20 | AC | 18 ms
6,940 KB |
testcase_21 | AC | 17 ms
6,944 KB |
testcase_22 | AC | 19 ms
6,944 KB |
testcase_23 | AC | 18 ms
6,944 KB |
testcase_24 | AC | 19 ms
6,940 KB |
testcase_25 | AC | 19 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pll; typedef pair<ll, int> pli; typedef pair<int, int> pii; typedef pair<ll, ld> pld; typedef pair<pii, int> ppiii; typedef pair<pii, ll> ppiil; typedef pair<pll, ll> pplll; typedef pair<pli, int> pplii; typedef vector<vector<ll>> vvl; typedef vector<vector<int>> vvi; typedef vector<vector<pll>> vvpll; #define rep(i, a, b) for (ll i=(a); i<(b); i++) #define rrep(i, a, b) for (ll i=(a); i>(b); i--) #define pb push_back #define tostr to_string #define mkp make_pair #define list2d(name, N, M, type, init) vector<vector<type>> name(N, vector<type>(M, init)) const ll INF = LONG_LONG_MAX; const ll MOD = 998244353; void print(ld out) { cout << fixed << setprecision(15) << out << '\n'; } void print(double out) { cout << fixed << setprecision(15) << out << '\n'; } template<typename T> void print(T out) { cout << out << '\n'; } template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; } template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } } template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); } template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; } template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; } ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; } ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; } ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; } ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; } // 数字なら'0'、アルファベットなら'a'みたいに使い分ける // int toint(char c) { return c - '0'; } // char tochar(int i) { return '0' + i; } inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; } inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; } inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } } inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } } pll divmod(ll a, ll b) { ll d = a / b; ll m = a % b; return {d, m}; } int popcount(ll S) { return __builtin_popcountll(S); } ll gcd(ll a, ll b) { return __gcd(a, b); } #ifndef ATCODER_INTERNAL_SCC_HPP #define ATCODER_INTERNAL_SCC_HPP 1 #include <algorithm> #include <utility> #include <vector> namespace atcoder { namespace internal { template <class E> struct csr { std::vector<int> start; std::vector<E> elist; csr(int n, const std::vector<std::pair<int, E>>& edges) : start(n + 1), elist(edges.size()) { for (auto e : edges) { start[e.first + 1]++; } for (int i = 1; i <= n; i++) { start[i] += start[i - 1]; } auto counter = start; for (auto e : edges) { elist[counter[e.first]++] = e.second; } } }; // Reference: // R. Tarjan, // Depth-First Search and Linear Graph Algorithms struct scc_graph { public: scc_graph(int n) : _n(n) {} int num_vertices() { return _n; } void add_edge(int from, int to) { edges.push_back({from, {to}}); } // @return pair of (# of scc, scc id) std::pair<int, std::vector<int>> scc_ids() { auto g = csr<edge>(_n, edges); int now_ord = 0, group_num = 0; std::vector<int> visited, low(_n), ord(_n, -1), ids(_n); visited.reserve(_n); auto dfs = [&](auto self, int v) -> void { low[v] = ord[v] = now_ord++; visited.push_back(v); for (int i = g.start[v]; i < g.start[v + 1]; i++) { auto to = g.elist[i].to; if (ord[to] == -1) { self(self, to); low[v] = std::min(low[v], low[to]); } else { low[v] = std::min(low[v], ord[to]); } } if (low[v] == ord[v]) { while (true) { int u = visited.back(); visited.pop_back(); ord[u] = _n; ids[u] = group_num; if (u == v) break; } group_num++; } }; for (int i = 0; i < _n; i++) { if (ord[i] == -1) dfs(dfs, i); } for (auto& x : ids) { x = group_num - 1 - x; } return {group_num, ids}; } std::vector<std::vector<int>> scc() { auto ids = scc_ids(); int group_num = ids.first; std::vector<int> counts(group_num); for (auto x : ids.second) counts[x]++; std::vector<std::vector<int>> groups(ids.first); for (int i = 0; i < group_num; i++) { groups[i].reserve(counts[i]); } for (int i = 0; i < _n; i++) { groups[ids.second[i]].push_back(i); } return groups; } private: int _n; struct edge { int to; }; std::vector<std::pair<int, edge>> edges; }; } // namespace internal } // namespace atcoder #endif // ATCODER_INTERNAL_SCC_HPP #ifndef ATCODER_TWOSAT_HPP #define ATCODER_TWOSAT_HPP 1 #include <cassert> #include <vector> namespace atcoder { // Reference: // B. Aspvall, M. Plass, and R. Tarjan, // A Linear-Time Algorithm for Testing the Truth of Certain Quantified Boolean // Formulas struct two_sat { public: two_sat() : _n(0), scc(0) {} two_sat(int n) : _n(n), _answer(n), scc(2 * n) {} void add_clause(int i, bool f, int j, bool g) { assert(0 <= i && i < _n); assert(0 <= j && j < _n); scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0)); scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0)); } bool satisfiable() { auto id = scc.scc_ids().second; for (int i = 0; i < _n; i++) { if (id[2 * i] == id[2 * i + 1]) return false; _answer[i] = id[2 * i] < id[2 * i + 1]; } return true; } std::vector<bool> answer() { return _answer; } private: int _n; std::vector<bool> _answer; internal::scc_graph scc; }; } // namespace atcoder #endif // ATCODER_TWOSAT_HPP using namespace atcoder; ll N, M; vector<ll> L, R; bool check(ll l1, ll r1, ll l2, ll r2) { return (l1 >= r2 || l2 >= r1); } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> M; L.resize(N); R.resize(N); rep(i, 0, N) { cin >> L[i] >> R[i]; R[i]++; } // ts[i] := i行目を反転させるか two_sat ts(N); rep(i, 0, N) { rep(j, i+1, N) { // 0, 0 if (!check(L[i], R[i], L[j], R[j])) { // a & bがNGなら、!a | !bを条件に追加する ts.add_clause(i, 1, j, 1); } // 1, 0 if (!check(M-R[i], M-L[i], L[j], R[j])) { ts.add_clause(i, 0, j, 1); } // 0, 1 if (!check(L[i], R[i], M-R[j], M-L[j])) { ts.add_clause(i, 1, j, 0); } // 1, 1 if (!check(M-R[i], M-L[i], M-R[j], M-L[j])) { ts.add_clause(i, 0, j, 0); } } } if (ts.satisfiable()) { print("YES"); } else { print("NO"); } return 0; }