結果
問題 |
No.274 The Wall
|
ユーザー |
![]() |
提出日時 | 2020-01-09 12:58:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 114 ms / 2,000 ms |
コード長 | 1,918 bytes |
コンパイル時間 | 2,681 ms |
コンパイル使用メモリ | 81,808 KB |
実行使用メモリ | 53,076 KB |
最終ジャッジ日時 | 2025-03-17 19:04:30 |
合計ジャッジ時間 | 5,813 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 23 |
ソースコード
import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int n = Integer.parseInt(first[0]); int m = Integer.parseInt(first[1]); PriorityQueue<Block> queue = new PriorityQueue<>(); for (int i = 0; i < n; i++) { queue.add(new Block(m, br.readLine())); } int start = -1; while (queue.size() > 0) { Block b = queue.poll(); if (start < b.left) { start = b.right; } else { b.reverse(); if (start < b.left) { queue.add(b); } else { System.out.println("NO"); return; } } } System.out.println("YES"); } static class Block implements Comparable<Block> { int size; int left; int right; public Block(int size, String line) { this.size = size; String[] arr = line.split(" ", 2); left = Integer.parseInt(arr[0]); right = Integer.parseInt(arr[1]); if (left > size - right - 1) { reverse(); } } public int compareTo(Block another) { if (left == another.left) { return right - another.right; } else { return left - another.left; } } public void reverse() { int tmp = right; right = size - left - 1; left = size - tmp - 1; } public String toString() { return "size:" + size + " left:" + left + " right:" + right; } } }