結果

問題 No.274 The Wall
ユーザー syndromesyndrome
提出日時 2023-06-10 00:49:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 2,000 ms
コード長 4,038 bytes
コンパイル時間 2,538 ms
コンパイル使用メモリ 214,316 KB
実行使用メモリ 131,872 KB
最終ジャッジ日時 2023-08-30 15:43:08
合計ジャッジ時間 5,188 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 143 ms
69,508 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 398 ms
131,872 KB
testcase_12 AC 13 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 66 ms
26,792 KB
testcase_17 AC 63 ms
26,608 KB
testcase_18 AC 67 ms
27,744 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 13 ms
4,380 KB
testcase_21 AC 14 ms
4,376 KB
testcase_22 AC 14 ms
4,376 KB
testcase_23 AC 14 ms
4,380 KB
testcase_24 AC 14 ms
4,376 KB
testcase_25 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// (⁠◕⁠ᴗ⁠◕⁠✿⁠)

#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
// using mint = modint1000000007;
// using mint = modint998244353;
// using vmint = vc<mint>;using vvmint = vc<vmint>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srep(i, s, n) for (int i = s; i < n; i++)
#define drep(i, n) for (int i = n; i >= 0; i--)
#define dsrep(i, s, n) for (int i = s; i >= n; i--)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl
using namespace std;
template<typename T> using vc = vector<T>;
template<typename T> using vv = vc<vc<T>>;
using vi = vc<int>;using vvi = vv<int>; using vvvi = vv<vi>;
using ll = long long;using vl = vc<ll>;using vvl = vv<ll>; using vvvl = vv<vl>;
using ld = long double; using vld = vc<ld>; using vvld = vc<vld>; using vvvld = vc<vvld>;
using uint = unsigned int;
using ull = unsigned long long;
using pii = pair<int, int>;
const double pi = 3.141592653589793;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
// const int mod = 1000000007;
const int mod = 998244353;
inline bool inside(long long y, long long x, long long H, long long W) {return 0 <= y and y < H and 0 <= x and x < W; }

struct phash{
    inline size_t operator()(const pair<int,int> & p) const{
        const auto h1 = hash<int>()(p.first);
        const auto h2 = hash<int>()(p.second);
        return h1 ^ (h2 << 1);
    }
};

struct twosat{
    public :
        twosat(int n) : nn(n){
            _n = 2 * nn;
            group = vi(_n, -1);
            order = vi();
            order.clear();
            g = vvi(_n);
            rg = vvi(_n);
            label = 0;
            answer = vc<bool>(nn);
        }

        void add_edge(int u, int v){
            g[u].push_back(v);
            rg[v].push_back(u);
        }

        void dfs(int s){
            used[s] = true;
            for (auto t : g[s]){
                if (!used[t]) dfs(t);
            }
            order.push_back(s);
        }

        void rdfs(int s, int color){
            group[s] = color;
            nused[s] = true;
            for (auto t : rg[s]){
                if (!nused[t]) rdfs(t, color);
            }
        }

        void scc(){
            used = vc<bool>(_n);
            nused = vc<bool>(_n);
            rep(i, _n){
                if (!used[i]) dfs(i);
            }
            drep(i, len(order) - 1){
                if (!nused[order[i]]){
                    rdfs(order[i], label);
                    label++;
                }
            }
        }

        void add(int i, bool f, int j, bool g){
            add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
            add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
        }

        bool judge(){
            scc();
            rep(i, nn){
                if (group[2 * i] == group[2 * i + 1]) return false;
                answer[i] = group[2 * i] < group[2 * i + 1];
            }
            return true;
        }

        vc<bool> restore(){
            return answer;
        }
    
    private : 
        int _n, nn, label;
        vi order, group;
        vvi g, rg;
        vc<bool> used, nused, answer;
};

int main(){
    int N, M; cin >> N >> M;
    vc<pair<int, int>> pincs;
    rep(i, N){
        int l, r; cin >> l >> r;
        pincs.push_back({l, r});
    }
    twosat ts(N);
    rep(j, N) rep(i, j){
        auto [l1, r1] = pincs[i];
        auto [l2, r2] = pincs[j];
        if (max(l1, l2) <= min(r1, r2)){
            ts.add(i, 0, j, 0);
        }
        if (max(l1, M - 1 - r2) <= min(r1, M - 1 - l2)){
            ts.add(i, 0, j, 1);
        }
        if (max(M - 1 - r1, l2) <= min(M - 1 - l1, r2)){
            ts.add(i, 1, j, 0);
        }
        if (max(M - 1 - r1, M - 1 - r2) <= min(M - 1 - l1, M - 1 - l2)){
            ts.add(i, 1, j, 1);
        }
    }
    if (ts.judge()) cout << "YES" << endl;
    else cout << "NO" << endl;
}
0