結果

問題 No.274 The Wall
ユーザー Ymgch_KYmgch_K
提出日時 2017-06-22 13:38:23
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 3,323 bytes
コンパイル時間 1,953 ms
コンパイル使用メモリ 171,132 KB
実行使用メモリ 8,656 KB
最終ジャッジ日時 2023-09-04 02:22:21
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,204 KB
testcase_01 AC 4 ms
8,112 KB
testcase_02 AC 5 ms
8,108 KB
testcase_03 AC 5 ms
8,364 KB
testcase_04 AC 5 ms
8,328 KB
testcase_05 AC 4 ms
8,216 KB
testcase_06 AC 5 ms
8,240 KB
testcase_07 AC 5 ms
8,220 KB
testcase_08 AC 5 ms
8,224 KB
testcase_09 AC 5 ms
8,116 KB
testcase_10 AC 4 ms
8,164 KB
testcase_11 AC 6 ms
8,084 KB
testcase_12 AC 14 ms
8,220 KB
testcase_13 AC 5 ms
8,332 KB
testcase_14 AC 9 ms
8,324 KB
testcase_15 AC 14 ms
8,532 KB
testcase_16 AC 6 ms
8,092 KB
testcase_17 AC 6 ms
8,224 KB
testcase_18 AC 6 ms
8,296 KB
testcase_19 AC 23 ms
8,460 KB
testcase_20 AC 27 ms
8,484 KB
testcase_21 AC 27 ms
8,492 KB
testcase_22 AC 28 ms
8,656 KB
testcase_23 AC 28 ms
8,492 KB
testcase_24 AC 28 ms
8,508 KB
testcase_25 AC 29 ms
8,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define OUT(x) cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

int V;
vector<int> g[101010];
vector<int> rg[101010];
vector<int> order;
bool used[101010];
int cmp[101010];

void add_edge(int from, int to) {
        g[from].push_back(to);
        rg[to].push_back(from);
}
void dfs(int v) {
        used[v] = true;
        for (auto i : g[v]) if (!used[i]) dfs(i);
        order.push_back(v);
}
void rdfs(int v, int k) {
        used[v] = true;
        cmp[v] = k;
        for (auto i : rg[v]) if (!used[i]) rdfs(i, k);
}
int StronglyConnectedComponent() {
        memset(used, 0, sizeof(used));
        order.clear();
        for (int i = 0; i < V; i ++) if (!used[i]) dfs(i);
        memset(used, 0, sizeof(used));
        int k = 0;
        for (int i = order.size() - 1; i >= 0; i --) if (!used[order[i]]) rdfs(order[i], k ++);
        return k;
}

bool chofuku(int l, int r, int s, int t) {
        if ((l <= s && s <= r) || (s <= l && l <= t) || (l <= s && t <= r) || (s <= l && r <= t)) return true;
        return false;
}

signed main() { 
        int n, m;
        cin >> n >> m;
        V = 2 * n;
        vector<int> l(n), r(n);
        rep(i, n) {
                int ll, rr;
                cin >> ll >> rr;
                l[i] = ll;
                r[i] = rr;
        }
        rep(i, n) for (int j = i + 1; j < n; j ++) {
                int ll = m - r[i] - 1, rr = m - l[i] - 1;
                //OUT(ll);
                //OUT(rr);
                //OUT(l[i]);
                //OUT(r[i]);
                //OUT(l[j]);
                //OUT(r[j]);
                if (chofuku(l[i], r[i], l[j], r[j]) && chofuku(ll, rr, l[j], r[j])) {
                        cout << "NO" << endl;
                        return 0;
                } else if (chofuku(l[i], r[i], l[j], r[j]) && !chofuku(ll, rr, l[j], r[j])) {
                        add_edge(i, j + n);
                        add_edge(j + n, i);
                        add_edge(j, i + n);
                        add_edge(i + n, j);
                } else if (!chofuku(l[i], r[i], l[j], r[j]) && chofuku(ll, rr, l[j], r[j])) {
                        add_edge(i, j);
                        add_edge(j, i);
                        add_edge(i + n, j + n);
                        add_edge(j + n, i + n);
                }
        }
        StronglyConnectedComponent();
        rep(i, n) {
                if (cmp[i] == cmp[i + n]) {
                        cout << "NO" << endl;
                        return 0;
                }
        }
        cout << "YES" << endl;
        return 0;
}               
0