結果

問題 No.274 The Wall
ユーザー koyumeishikoyumeishi
提出日時 2015-08-28 23:14:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,428 bytes
コンパイル時間 734 ms
コンパイル使用メモリ 83,612 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-04 01:59:26
合計ジャッジ時間 1,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 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 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

bool comp(const pair<int,int>& x, const pair<int,int>& y){
	if(x.second != y.second) return x.second < y.second;
	else return x.first < y.first;
}

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> L(n),R(n);
	for(int i=0; i<n; i++){
		cin >> L[i] >> R[i];
	}

	vector<pair<int,int>> v(n);
	for(int i=0; i<n; i++){
		if(L[i] >= m/2){
			swap(L[i], R[i]);
			L[i] = m-1 - L[i];
			R[i] = m-1 - R[i];
		}
		v[i] = {L[i], R[i]};
	}

	sort(v.begin(), v.end(), comp);
	vector<pair<int,int>> next;
	next.push_back({-1,m});
	for(int i=0; i<n; i++){
		vector<pair<int,int>> next_;
		int r__ = m;
		int l__ = -1;

		int l = v[i].first;
		int r = v[i].second;
		
		int rl = m-1 - r;
		int rr = m-1 - l;

		for(int j=0; j<next.size(); j++){

			if(next[j].first < l && r < next[j].second){
				l__ = max(next[j].second, l__);
				//next_.push_back({r, next[j].second});
			}

			if(next[j].first < rl && rr < next[j].second){
				r__ = min(next[j].first, r__);
				//next_.push_back({next[j].first, rl});
			}
		}

		if(l__ != -1){
			next_.push_back({r, l__});
		}
		if(r__ != m){
			next_.push_back({r__, rl});
		}
		swap(next, next_);
	}

	if(next.size() == 0){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}

	return 0;
}
0