結果

問題 No.274 The Wall
ユーザー pekempeypekempey
提出日時 2015-08-29 11:05:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 537 ms / 2,000 ms
コード長 1,548 bytes
コンパイル時間 1,266 ms
コンパイル使用メモリ 153,576 KB
実行使用メモリ 132,048 KB
最終ジャッジ日時 2023-09-04 02:04:48
合計ジャッジ時間 3,745 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 161 ms
69,664 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 537 ms
132,048 KB
testcase_12 AC 21 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 8 ms
4,376 KB
testcase_15 AC 20 ms
4,376 KB
testcase_16 AC 129 ms
38,236 KB
testcase_17 AC 120 ms
36,656 KB
testcase_18 AC 129 ms
39,716 KB
testcase_19 AC 36 ms
4,376 KB
testcase_20 AC 42 ms
4,376 KB
testcase_21 AC 43 ms
4,376 KB
testcase_22 AC 45 ms
4,380 KB
testcase_23 AC 46 ms
4,380 KB
testcase_24 AC 45 ms
4,376 KB
testcase_25 AC 45 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a) rep2 (i, 0, a)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define repr(i, a) repr2 (i, 0, a)
#define repr2(i, a, b) for (int i = (b) - 1; i >= (a); i--)
using namespace std;
typedef long long ll;

class SCC {
public:
	vector<int> cc;
	SCC(int n) : G(n), H(n), vis(n), cc(n, -1) {}
	void add(int u, int v) {
		G[u].push_back(v);
		H[v].push_back(u);
	}
	void build() {
		rep (i, G.size()) if (!vis[i]) {
			dfs(i);
		}
		int k = 0;
		repr (i, order.size()) if (cc[order[i]] == -1) {
			dfs2(order[i], k++);
		}
	}
private:
	vector<vector<int>> G, H;
	vector<bool> vis;
	vector<int> order;
	void dfs(int curr) {
		vis[curr] = true;
		for (int next : G[curr]) if (!vis[next]) {
			dfs(next);
		}
		order.push_back(curr);
	}
	void dfs2(int curr, int k) {
		cc[curr] = k;
		for (int next : H[curr]) if (cc[next] == -1) {
			dfs2(next, k);
		}
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	SCC scc(N * 2);
	vector<int> L[2], R[2];
	rep (i, 2) {
		L[i].resize(N);
		R[i].resize(N);
	}
	rep (i, N) scanf("%d%d", &L[0][i], &R[0][i]);
	rep (i, N) {
		R[1][i] = M - 1 - L[0][i];
		L[1][i] = M - 1 - R[0][i];
	}
	rep (i, N) rep (j, 2) rep (k, i) rep (l, 2) {
		if (i == k) continue;
		if (L[j][i] <= R[l][k] && R[j][i] >= L[l][k]) {
			scc.add(i + N * j, k + N * !l);
			scc.add(k + N * l, i + N * !j);
		}
	}
	scc.build();
	bool all = true;
	rep (i, N) {
		if (scc.cc[i] == scc.cc[i + N]) {
			all = false;
		}
	}
	if (all) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
    return 0;
}
0