結果

問題 No.274 The Wall
ユーザー htensaihtensai
提出日時 2020-01-09 12:58:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,918 bytes
コンパイル時間 3,709 ms
コンパイル使用メモリ 77,076 KB
実行使用メモリ 55,332 KB
最終ジャッジ日時 2023-09-04 02:46:59
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,892 KB
testcase_01 AC 46 ms
49,496 KB
testcase_02 AC 47 ms
49,508 KB
testcase_03 AC 67 ms
50,520 KB
testcase_04 AC 46 ms
49,640 KB
testcase_05 AC 46 ms
49,544 KB
testcase_06 AC 46 ms
49,428 KB
testcase_07 AC 47 ms
49,440 KB
testcase_08 AC 46 ms
49,440 KB
testcase_09 AC 46 ms
49,892 KB
testcase_10 AC 45 ms
49,444 KB
testcase_11 AC 78 ms
52,600 KB
testcase_12 AC 88 ms
53,300 KB
testcase_13 AC 53 ms
49,688 KB
testcase_14 AC 80 ms
51,660 KB
testcase_15 AC 83 ms
52,404 KB
testcase_16 AC 82 ms
52,024 KB
testcase_17 AC 79 ms
52,332 KB
testcase_18 AC 81 ms
51,436 KB
testcase_19 AC 105 ms
52,964 KB
testcase_20 AC 109 ms
53,016 KB
testcase_21 AC 107 ms
53,108 KB
testcase_22 AC 111 ms
52,368 KB
testcase_23 AC 89 ms
52,160 KB
testcase_24 AC 107 ms
52,952 KB
testcase_25 AC 110 ms
55,332 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
    }
}
0