結果

問題 No.274 The Wall
ユーザー hirokazu1020hirokazu1020
提出日時 2015-08-29 00:04:22
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,780 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 80,596 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 02:02:05
合計ジャッジ時間 1,683 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())
#define indexOf(v,x) (find(all(v),x)-v.begin())



int n,m;
pair<int,int> b[2000];


bool cmp(pair<int,int> a,pair<int,int> b){
	int x=min(a.first,m-1-a.second);
	int y=min(b.first,m-1-b.second);
	return x<y;
}

int main(){	
	cin>>n>>m;
	rep(i,n)cin>>b[i].first>>b[i].second;
	sort(b,b+n,cmp);
	bool used[2000]={};
	bool filled[4000]={};
	rep(i,n){
		bool ok=true;
		if(b[i].first < m-1-b[i].second){
			for(int j=b[i].first;j<=b[i].second;j++){
				if(filled[j])ok=false;
			}
			if(ok){
				for(int j=b[i].first;j<=b[i].second;j++){
					filled[j]=true;
				}
				used[i]=true;
			}
		}else{
			for(int j=m-1-b[i].second;j<=m-1-b[i].first;j++){
				if(filled[j])ok=false;
			}
			if(ok){
				for(int j=m-1-b[i].second;j<=m-1-b[i].first;j++){
					filled[j]=true;
				}
				used[i]=true;
			}
		}
	}
	rep(i,n){
		if(used[i])continue;
		bool ok=true;
		if(b[i].first < m-1-b[i].second){
			for(int j=m-1-b[i].second;j<=m-1-b[i].first;j++){
				if(filled[j])ok=false;
			}
			if(ok){
				for(int j=m-1-b[i].second;j<=m-1-b[i].first;j++){
					filled[j]=true;
				}
				used[i]=true;
			}
		}else{
			for(int j=b[i].first;j<=b[i].second;j++){
				if(filled[j])ok=false;
			}
			if(ok){
				for(int j=b[i].first;j<=b[i].second;j++){
					filled[j]=true;
				}
				used[i]=true;
			}
		}
	}
	cout<<(count(used,used+n,true)==n?"YES":"NO")<<endl;
	return 0;
}
0