結果

問題 No.274 The Wall
ユーザー りりんばる
提出日時 2023-10-19 11:35:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 220 ms / 2,000 ms
コード長 1,988 bytes
コンパイル時間 1,816 ms
コンパイル使用メモリ 177,928 KB
実行使用メモリ 132,224 KB
最終ジャッジ日時 2025-03-17 19:12:39
合計ジャッジ時間 3,144 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, p, n) for (ll i = p; i < (ll)(n); i++)
#define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--)
using namespace std;
using ll = long long;
double pi = 3.141592653589793;
const long long inf = 2 * 1e9;
const long long linf = 8 * 1e18;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
// atcoder
#include <atcoder/modint>
#include <atcoder/dsu>
using namespace atcoder;
using mint1 = modint1000000007;
using mint2 = modint998244353;

int main(){
    ll N, M;
    cin >> N >> M;
    vector<pair<ll, ll>> P(N);
    rep(i, 0, N) {
        cin >> P.at(i).first >> P.at(i).second;
    }
    vector<vector<ll>> G(N*2);
    rep(i, 0, N) {
        rep(j, i+1, N) {
            if (!(P.at(i).second<P.at(j).first || P.at(j).second<P.at(i).first)) {
                G.at(i).push_back(j + N);
                G.at(j + N).push_back(i);
                G.at(j).push_back(i + N);
                G.at(i + N).push_back(j);
            }
            if (!(M - 1 - P.at(i).first < P.at(j).first || P.at(j).second < M - 1 - P.at(i).second)) {
                G.at(i+N).push_back(j + N);
                G.at(j + N).push_back(i+N);
                G.at(j).push_back(i);
                G.at(i).push_back(j);
            }
        }
    }
    queue<ll> Q;
    vector<ll> ch(2*N, -1);
    ll now = 0;
    rep(i, 0, N*2) {
        if (ch.at(i)==-1) {
        	ch.at(i)=now;
            Q.push(i);
            while(Q.size()) {
                ll P = Q.front();
                Q.pop();
                for(int c:G.at(P)) {
                    if (ch.at(c)==-1) {
                        ch.at(c) = now;
                        Q.push(c);
                    }
                }
            }
            now++;
        }
    }
    rep(i, 0, N) {
        if (ch.at(i)==ch.at(i+N)) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}
0