結果

問題 No.274 The Wall
ユーザー femtofemto
提出日時 2017-03-10 17:03:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,050 bytes
コンパイル時間 2,560 ms
コンパイル使用メモリ 180,796 KB
実行使用メモリ 324,128 KB
最終ジャッジ日時 2023-09-06 13:17:57
合計ジャッジ時間 5,170 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 189 ms
91,916 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 753 ms
324,128 KB
testcase_12 AC 4 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 7 ms
4,376 KB
testcase_16 AC 168 ms
84,288 KB
testcase_17 AC 160 ms
80,696 KB
testcase_18 AC 176 ms
87,464 KB
testcase_19 AC 13 ms
4,380 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 15 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 15 ms
4,384 KB
testcase_25 AC 16 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


struct edge {
	int src, dst;
	edge(int src, int dst) :
		src(src), dst(dst) {
	}
};
typedef vector<edge> edges;
typedef vector<edges> Graph;

#define VAR(x) ((x) << 1)
#define NOT(x) ((x) ^ 1) // !a = NOT(VAR(a))
void visit(int v, const Graph &g, vector<int> &ord, vector<int> &num, int k) {
	if(num[v] >= 0) return;
	num[v] = k;
	for(int i = 0; i < g[v].size(); ++i)
		visit(g[v][i].dst, g, ord, num, k);
	ord.push_back(v);
}

typedef pair<int, int> clause; // {a or b}

pair<bool, vector<bool>> two_satisfiability(int m, const vector<clause> &cs) {
	int n = m * 2; // m positive vars and m negative vars
	Graph g(n), h(n);
	for(int i = 0; i < cs.size(); ++i) {
		int u = cs[i].first, v = cs[i].second;
		g[NOT(u)].push_back(edge(NOT(u), v));
		g[NOT(v)].push_back(edge(NOT(v), u));
		h[v].push_back(edge(v, NOT(u)));
		h[u].push_back(edge(u, NOT(v)));
	}
	vector<int> num(n, -1), ord, dro;
	for(int i = 0; i < n; ++i)
		visit(i, g, ord, num, i);
	reverse(ord.begin(), ord.end());
	fill(num.begin(), num.end(), -1);
	for(int i = 0; i < n; ++i)
		visit(ord[i], h, dro, num, i);
	for(int i = 0; i < n; ++i) {
		if(num[i] == num[NOT(i)]) return{ false, vector<bool>() };
	}

	vector<bool> T(m);
	for(int i = 0; i < m; i++) {
		if(num[VAR(i)] > num[NOT(VAR(i))]) T[i] = 1;
	}
	return{ true, T };
}


int L[2000];
int R[2000];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	for(int i = 0; i < N; i++) {
		cin >> L[i] >> R[i];
	}

	vector<clause> cs;
	for(int i = 0; i < N; i++) {
		for(int j = i + 1; j < N; j++) {
			if(!(R[i] < L[j] || R[j] < L[i])) {
				cs.push_back({ NOT(VAR(i)), VAR(j) });
				cs.push_back({ VAR(i), NOT(VAR(j)) });
			}
			int l = M - R[j] + 1, r = M - L[j] + 1;
			if(!(R[i] < l || r < L[i])) {
				cs.push_back({ VAR(i), VAR(j) });
				cs.push_back({ NOT(VAR(i)), NOT(VAR(j)) });
				
			}
		}
	}

	auto res = two_satisfiability(N, cs);
	if(res.first) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}
0