結果

問題 No.274 The Wall
ユーザー minamiminami
提出日時 2017-02-20 12:41:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 2,427 bytes
コンパイル時間 2,150 ms
コンパイル使用メモリ 174,812 KB
実行使用メモリ 67,920 KB
最終ジャッジ日時 2023-09-04 02:15:32
合計ジャッジ時間 3,736 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 73 ms
36,732 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 202 ms
67,920 KB
testcase_12 AC 24 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 16 ms
4,380 KB
testcase_16 AC 70 ms
21,148 KB
testcase_17 AC 65 ms
20,592 KB
testcase_18 AC 68 ms
21,584 KB
testcase_19 AC 28 ms
4,376 KB
testcase_20 AC 32 ms
4,376 KB
testcase_21 AC 32 ms
4,376 KB
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 35 ms
4,376 KB
testcase_24 AC 35 ms
4,376 KB
testcase_25 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

void visit(const vector<vector<int>> &g, int v,
	vector<int> &scccolor, int &colors,
	vector<int> &S, vector<char> &inS,
	vector<int> &low, vector<int> &num, int &time) {
	low[v] = num[v] = ++time;
	S.push_back(v); inS[v] = true;
	for (auto &e : g[v]) {
		int w = e;
		if (num[w] == 0) {
			visit(g, w, scccolor, colors, S, inS, low, num, time);
			low[v] = min(low[v], low[w]);
		}
		else if (inS[w])
			low[v] = min(low[v], num[w]);
	}
	if (low[v] == num[v]) {
		while (1) {
			int w = S.back(); S.pop_back(); inS[w] = false;
			scccolor[w] = colors;
			if (v == w) break;
		}
		colors++;
	}
}
int strongly_connected_components(const vector<vector<int>> &g, vector<int> &scccolor) {
	const int n = g.size();
	vector<int> num(n), low(n);
	vector<int> S;
	vector<char> inS(n);
	scccolor.resize(n);
	int time = 0, colors = 0;
	rep(u, 0, n) if (num[u] == 0)
		visit(g, u, scccolor, colors, S, inS, low, num, time);
	return colors;
}

bool two_satisfiability(const vector<vector<int>> &g) {
	int n = g.size() / 2;
	vector<int> scccolor;
	strongly_connected_components(g, scccolor);
	rep(i, 0, n) if (scccolor[i] == scccolor[n + i]) return false;
	return true;
}


bool f(int a, int b, int c, int d) {
	return c <= b && a <= d;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	while (cin >> N >> M) {
		vector<int> L(N), R(N); rep(i, 0, N) { cin >> L[i] >> R[i]; }
		vector<vector<int>> g(N * 2);
		rep(i, 0, N) rep(j, 0, i) {
			int a = L[i], b = R[i], c = L[j], d = R[j];
			rep(x, 0, 2) {
				rep(y, 0, 2) {
					if (f(a, b, c, d)) { //制約
						g[(1 - x) * N + i].push_back(y * N + j);
						g[(1 - y) * N + j].push_back(x * N + i);
					}
					a = M - 1 - a, b = M - 1 - b, swap(a, b);
				}
				c = M - 1 - c, d = M - 1 - d, swap(c, d);
			}
		}
		cout << (two_satisfiability(g) ? "YES" : "NO") << endl;
	}
	return 0;
}
0