結果

問題 No.274 The Wall
ユーザー femtofemto
提出日時 2017-03-10 16:54:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,878 bytes
コンパイル時間 1,579 ms
コンパイル使用メモリ 179,988 KB
実行使用メモリ 163,584 KB
最終ジャッジ日時 2023-09-06 13:17:24
合計ジャッジ時間 4,374 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 136 ms
80,804 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 377 ms
163,584 KB
testcase_12 AC 5 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 AC 85 ms
45,860 KB
testcase_17 AC 83 ms
43,644 KB
testcase_18 AC 87 ms
47,372 KB
testcase_19 AC 8 ms
4,376 KB
testcase_20 AC 9 ms
4,376 KB
testcase_21 AC 9 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 10 ms
4,380 KB
testcase_25 AC 10 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]) continue;
			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