結果

問題 No.274 The Wall
ユーザー pazzle1230pazzle1230
提出日時 2017-09-14 03:00:40
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 3,359 bytes
コンパイル時間 2,575 ms
コンパイル使用メモリ 112,364 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 02:26:08
合計ジャッジ時間 4,052 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 41 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 12 ms
4,376 KB
testcase_15 AC 27 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 48 ms
4,380 KB
testcase_20 AC 57 ms
4,380 KB
testcase_21 AC 59 ms
4,376 KB
testcase_22 AC 62 ms
4,376 KB
testcase_23 AC 62 ms
4,376 KB
testcase_24 AC 63 ms
4,376 KB
testcase_25 AC 63 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class SCC{
private:
	vector<vector<int> > gg, rg;
	vector<int> order, comp;
	vector<bool> used;
	vector<vector<int> > ng, vs;

	int n, nn;
public:
	SCC(){}
	SCC(int v) : gg(v), rg(v), comp(v, -1), used(v, 0), n(v){}

	void add_edge(int x, int y){
		gg[x].push_back(y);
		rg[y].push_back(x);
	}

	int operator[](int k){
		return comp[k];
	}

	void dfs(int v){
		used[v] = true;
		REP(i, gg[v].size()){
			if(!used[gg[v][i]]) dfs(gg[v][i]);
		}
		order.push_back(v);
	}

	void rdfs(int v, int k){
		used[v] = true;
		comp[v] = k;
		REP(i, rg[v].size()){
			if(!used[rg[v][i]]) rdfs(rg[v][i], k);
		}
	}

	int build(){
		REP(i, n){
			if(!used[i]) dfs(i);
		}
		fill(all(used), 0);
		int k = 0;
		for(int i = order.size()-1;i >= 0;i--){
			if(!used[order[i]]) rdfs(order[i], k++);
		}
		nn = k;

		//---------それぞれの強連結成分に含まれる頂点の番号----------
		vs.resize(k, vector<int>());

		REP(i, n)
			vs[comp[i]].push_back(i);
		//-----------------------------------------------------------

		//---------強連結成分をまとめた後のNew Graph!----------------
		ng.resize(k, vector<int>());
		REP(i, n){
			REP(j, gg[i].size()){
				if(comp[i] != comp[gg[i][j]])
					ng[comp[i]].push_back(comp[gg[i][j]]);
			}
		}
		REP(i, nn){
			sort(all(ng[i]));
			ng[i].erase(unique(all(ng[i])), ng[i].end());
		}
		//------------------------------------------------------------
		return k;
	}
	
	int size(){
		return nn;
	}

	vector<vector<int> > graph(){
		return ng;
	}

	vector<int> vertices(int v){
		return vs[v];
	}
};
bool conflict(PII a, PII b){
	return ((a.first <= b.first && b.first <= a.second) || (a.first <= b.second && b.second <= a.second) || (b.first <= a.first && a.first <= b.second) || (b.first <= a.second && a.second <= b.second));
}

PII flip(PII a, int m){
	return {m-1-a.second, m-a.first-1};
}

int main(void){
	int n, m;
	PII b[4010];
	cin >> n >> m;
	
	SCC scc(2*n);
	REP(i, n){
		cin >> b[i].first >> b[i].second;
		b[i+n] = flip(b[i], m);
	}
	REP(i, n){
		REP(j, n){
			if(i == j) continue;
			int cnt = 0;
			if(conflict(b[i], b[j])){
				scc.add_edge(i, j+n);
				scc.add_edge(j, i+n);
				cnt++;
			}
			if(conflict(b[i], flip(b[j], m))){
				scc.add_edge(i, j);
				scc.add_edge(j+n, i+n);
				cnt++;
			}
			if(conflict(flip(b[i], m), b[j])){
				scc.add_edge(i+n, j+n);
				scc.add_edge(j, i);
				cnt++;
			}
			if(conflict(flip(b[i], m), flip(b[j], m))){
				scc.add_edge(i+n, j);
				scc.add_edge(j+n, i);
				cnt++;
			}
			if(cnt == 4){
				cout << "NO" << endl;
				return 0;
			}
		}
	}
	scc.build();
	REP(i, n){
		if(scc[i] == scc[i+n]){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}
0