結果

問題 No.274 The Wall
ユーザー ぴろずぴろず
提出日時 2015-08-28 22:59:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 1,198 bytes
コンパイル時間 3,364 ms
コンパイル使用メモリ 77,196 KB
実行使用メモリ 59,304 KB
最終ジャッジ日時 2023-09-04 01:58:37
合計ジャッジ時間 9,501 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
55,412 KB
testcase_01 AC 131 ms
55,464 KB
testcase_02 AC 131 ms
55,456 KB
testcase_03 AC 204 ms
57,888 KB
testcase_04 AC 131 ms
55,456 KB
testcase_05 AC 130 ms
55,428 KB
testcase_06 AC 131 ms
55,452 KB
testcase_07 AC 132 ms
55,432 KB
testcase_08 AC 133 ms
55,600 KB
testcase_09 AC 134 ms
55,444 KB
testcase_10 AC 132 ms
55,468 KB
testcase_11 AC 212 ms
58,680 KB
testcase_12 AC 224 ms
59,032 KB
testcase_13 AC 161 ms
55,656 KB
testcase_14 AC 204 ms
58,444 KB
testcase_15 AC 213 ms
58,220 KB
testcase_16 AC 221 ms
58,784 KB
testcase_17 AC 217 ms
58,512 KB
testcase_18 AC 222 ms
58,724 KB
testcase_19 AC 222 ms
58,848 KB
testcase_20 AC 223 ms
58,684 KB
testcase_21 AC 223 ms
58,584 KB
testcase_22 AC 230 ms
59,132 KB
testcase_23 AC 224 ms
59,224 KB
testcase_24 AC 230 ms
59,304 KB
testcase_25 AC 228 ms
58,992 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no274;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		System.out.println(new Main().solve() ? "YES" : "NO");
	}

	int m;

	public boolean solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		m = sc.nextInt();
		Block[] b = new Block[n];
		for(int i=0;i<n;i++) {
			b[i] = new Block(sc.nextInt(),sc.nextInt());
		}
		Arrays.sort(b);
		int l = 0;
		int r = m-1;
		for(int i=0;i<n;i++) {
			int bl = b[i].l;
			int br = b[i].r;
			if (l <= bl) {
				if (br > r) {
					return false;
				}
				l = br + 1;
			}else{
				int temp = bl;
				bl = m - 1 - br;
				br = m - 1 - temp;
				if (l <= bl && br <= r) {
					r = bl - 1;
				}else{
					return false;
				}
			}
		}
		return true;
	}

	class Block implements Comparable<Block>{
		int l,r;
		public Block(int l,int r) {
			if (l <= m-1-r) {
				this.l = l;
				this.r = r;
			}else{
				this.l = m - 1 - r;
				this.r = m - 1 - l;
			}
		}
		public int compareTo(Block o) {
			if (l != o.l) {
				return Integer.compare(l, o.l);
			}
			return Integer.compare(r, o.r);
		}
		public String toString() {
			return "[" + l + "," + r + "]";
		}
	}

}
0