結果

問題 No.274 The Wall
ユーザー ぴろずぴろず
提出日時 2015-08-28 22:51:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,177 bytes
コンパイル時間 3,997 ms
コンパイル使用メモリ 76,368 KB
実行使用メモリ 59,468 KB
最終ジャッジ日時 2023-09-25 19:24:44
合計ジャッジ時間 10,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
53,584 KB
testcase_01 AC 127 ms
55,996 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 125 ms
56,124 KB
testcase_06 WA -
testcase_07 AC 127 ms
55,868 KB
testcase_08 AC 125 ms
55,776 KB
testcase_09 AC 127 ms
56,584 KB
testcase_10 AC 126 ms
55,932 KB
testcase_11 AC 213 ms
58,900 KB
testcase_12 AC 213 ms
58,676 KB
testcase_13 AC 154 ms
56,020 KB
testcase_14 AC 199 ms
58,828 KB
testcase_15 AC 205 ms
58,312 KB
testcase_16 AC 214 ms
58,868 KB
testcase_17 AC 213 ms
59,008 KB
testcase_18 AC 216 ms
58,704 KB
testcase_19 AC 216 ms
59,048 KB
testcase_20 AC 216 ms
57,096 KB
testcase_21 AC 221 ms
59,364 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 216 ms
59,012 KB
testcase_25 AC 219 ms
58,856 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{
				bl = m - 1 - bl;
				br = m - 1 - br;
				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