結果

問題 No.274 The Wall
ユーザー fal_rnd
提出日時 2016-10-29 17:57:14
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,740 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 78,112 KB
実行使用メモリ 58,988 KB
最終ジャッジ日時 2024-11-24 18:05:44
合計ジャッジ時間 8,955 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
class A{
	static Scanner s = new Scanner(System.in);

	static boolean b[];

	public static void main(String[] args) {
		Blocks[] blocks				= new Blocks[s.nextInt()];
		int m=s.nextInt();
		b = new boolean[m];
		for (int i=0; i<blocks.length; i++) {
			int pl=s.nextInt(), pr=s.nextInt();
			Blocks
			b1 = new Blocks(m, pl, pr),
			b2 = b1.getReversedBlocks();

			blocks         [i] = max(b1,b2);
		}
		Arrays.sort(blocks);

		for(Blocks bl:blocks) {
			if(checkPuttable(bl)) {
				put(bl);
			}else {
				Blocks b = bl.getReversedBlocks();
				if(checkPuttable(b)){
					put(b);
				}else {
					System.out.println("NO");
					return;
				}
			}
		}
		System.out.println("YES");
	}
	static boolean checkPuttable(Blocks blocks) {
		for(int i=blocks.pl; i<=blocks.pr; i++) {
			if(b[i])
				return false;
		}
		return true;
	}
	static void put(Blocks blocks) {
		for(int i=blocks.pl; i<=blocks.pr; i++) {
			b[i]=true;
		}
	}

	static <T extends Comparable<T>> T max(T t1, T t2){
		if(t1.compareTo(t2)>=0)
			return t1;
		else
			return t2;
	}
	static <T extends Comparable<T>> T min(T t1, T t2){
		if(t1.compareTo(t2)<=0)
			return t1;
		else
			return t2;
	}
}
class Blocks implements Comparable<Blocks>{
	int length,pl,pr;
	Blocks(int m, int pl, int pr) {
		this.length	= m;
		this.pl		= pl;
		this.pr		= pr;
	}
	boolean isPainted(int i) {
		return (i>=this.pl)&&(i<=this.pr);
	}
	@Override
	public int compareTo(Blocks o) {
		for(int i=0; i<this.length; i++) {
			if(this.isPainted(i) != o.isPainted(i)) {
				if(this.isPainted(i)==true)
					return 1;
				else
					return -1;
			}
		}
		return 0;
	}
	Blocks getReversedBlocks() {
		return new Blocks(this.length, this.length-this.pr-1, this.length-this.pl-1);
	}
}
0