結果

問題 No.274 The Wall
ユーザー pekempeypekempey
提出日時 2015-08-29 11:02:37
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,218 ms / 2,000 ms
コード長 1,540 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 153,384 KB
実行使用メモリ 260,872 KB
最終ジャッジ日時 2023-09-04 02:04:43
合計ジャッジ時間 5,641 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 347 ms
127,096 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,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1,218 ms
260,872 KB
testcase_12 AC 38 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 14 ms
4,376 KB
testcase_15 AC 35 ms
4,376 KB
testcase_16 AC 278 ms
71,340 KB
testcase_17 AC 262 ms
68,204 KB
testcase_18 AC 283 ms
73,504 KB
testcase_19 AC 65 ms
4,376 KB
testcase_20 AC 76 ms
4,380 KB
testcase_21 AC 78 ms
4,380 KB
testcase_22 AC 83 ms
4,376 KB
testcase_23 AC 83 ms
4,380 KB
testcase_24 AC 83 ms
4,376 KB
testcase_25 AC 83 ms
4,380 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) cin >> 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, N) 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