結果

問題 No.274 The Wall
ユーザー kazumakazuma
提出日時 2017-06-25 20:31:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 347 ms / 2,000 ms
コード長 1,771 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 175,300 KB
実行使用メモリ 132,364 KB
最終ジャッジ日時 2023-09-04 02:22:25
合計ジャッジ時間 3,910 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 132 ms
63,024 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 347 ms
132,364 KB
testcase_12 AC 12 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 5 ms
4,376 KB
testcase_15 AC 11 ms
4,380 KB
testcase_16 AC 98 ms
37,176 KB
testcase_17 AC 91 ms
35,528 KB
testcase_18 AC 99 ms
38,172 KB
testcase_19 AC 18 ms
4,376 KB
testcase_20 AC 21 ms
4,376 KB
testcase_21 AC 22 ms
4,380 KB
testcase_22 AC 23 ms
4,380 KB
testcase_23 AC 24 ms
4,380 KB
testcase_24 AC 23 ms
4,380 KB
testcase_25 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Edge {
	int from, to;
	Edge(int f, int t) : from(f), to(t) {}
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

vector<int> tarjan(const Graph& g) {
	int n = g.size(), idx = 0, k = 0, s = 0;
	vector<int>ord(n, -1), low(n), onS(n), cmp(n), stk(n);
	function<void(int)> dfs = [&](int v) {
		ord[v] = low[v] = idx++;
		stk[s++] = v;
		onS[v] = true;
		for (auto &e : g[v]) {
			int w = e.to;
			if (ord[w] == -1) {
				dfs(w);
				low[v] = min(low[v], low[w]);
			}
			else if (onS[w]) {
				low[v] = min(low[v], ord[w]);
			}
		}
		if (low[v] == ord[v]) {
			while (1) {
				int w = stk[--s];
				onS[w] = false;
				cmp[w] = k;
				if (w == v)break;
			}
			++k;
		}
	};
	for (int v = 0; v<n; ++v)
		if (ord[v] == -1)dfs(v);
	return cmp;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> L1(N), R1(N);
	vector<int> L2(N), R2(N);
	for (int i = 0; i < N; i++) {
		cin >> L1[i] >> R1[i];
		R2[i] = M - 1 - L1[i];
		L2[i] = M - 1 - R1[i];
	}
	Graph G(N * 2);
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (!(R1[i] < L1[j] || R1[j] < L1[i])) {
				G[i].push_back(Edge(i, N + j));
				G[j].push_back(Edge(j, N + i));
			}
			if (!(R1[i] < L2[j] || R2[j] < L1[i])) {
				G[i].push_back(Edge(i, j));
				G[N + j].push_back(Edge(N + j, N + i));
			}
			if (!(R2[i] < L1[j] || R1[j] < L2[i])) {
				G[N + i].push_back(Edge(N + i, N + j));
				G[j].push_back(Edge(j, i));
			}
			if (!(R2[i] < L2[j] || R2[j] < L2[i])) {
				G[N + i].push_back(Edge(N + i, j));
				G[N + j].push_back(Edge(N + j, i));
			}
		}
	}
	auto v = tarjan(G);
	bool res = true;
	for (int i = 0; i < N; i++) {
		if (v[i] == v[i + N]) {
			res = false;
		}
	}
	cout << (res ? "YES" : "NO") << endl;
	return 0;
}
0