結果

問題 No.274 The Wall
ユーザー fal_rndfal_rnd
提出日時 2016-10-29 17:57:14
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,740 bytes
コンパイル時間 2,087 ms
コンパイル使用メモリ 78,764 KB
実行使用メモリ 60,000 KB
最終ジャッジ日時 2024-05-03 15:54:27
合計ジャッジ時間 8,426 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
54,080 KB
testcase_01 AC 117 ms
54,132 KB
testcase_02 AC 112 ms
54,020 KB
testcase_03 AC 181 ms
56,724 KB
testcase_04 AC 104 ms
52,892 KB
testcase_05 AC 114 ms
54,164 KB
testcase_06 AC 98 ms
52,904 KB
testcase_07 AC 121 ms
54,140 KB
testcase_08 AC 120 ms
53,880 KB
testcase_09 AC 124 ms
53,948 KB
testcase_10 AC 117 ms
54,260 KB
testcase_11 AC 266 ms
58,744 KB
testcase_12 AC 280 ms
58,680 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 258 ms
58,428 KB
testcase_17 AC 243 ms
57,904 KB
testcase_18 AC 240 ms
56,848 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 300 ms
58,452 KB
testcase_23 AC 279 ms
58,784 KB
testcase_24 WA -
testcase_25 WA -
権限があれば一括ダウンロードができます

ソースコード

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