結果

問題 No.274 The Wall
ユーザー りりんばるりりんばる
提出日時 2023-10-19 11:35:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,988 bytes
コンパイル時間 2,609 ms
コンパイル使用メモリ 184,268 KB
実行使用メモリ 132,528 KB
最終ジャッジ日時 2023-10-19 11:35:44
合計ジャッジ時間 4,293 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 97 ms
62,840 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 244 ms
132,528 KB
testcase_12 AC 6 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 4 ms
4,348 KB
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 67 ms
37,356 KB
testcase_17 AC 63 ms
35,508 KB
testcase_18 AC 69 ms
38,148 KB
testcase_19 AC 12 ms
4,348 KB
testcase_20 AC 14 ms
4,348 KB
testcase_21 AC 14 ms
4,348 KB
testcase_22 AC 15 ms
4,348 KB
testcase_23 AC 15 ms
4,348 KB
testcase_24 AC 15 ms
4,348 KB
testcase_25 AC 15 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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