結果

問題 No.274 The Wall
ユーザー KilisameKilisame
提出日時 2016-06-13 16:55:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 2,178 bytes
コンパイル時間 3,198 ms
コンパイル使用メモリ 81,288 KB
実行使用メモリ 58,672 KB
最終ジャッジ日時 2023-09-04 02:12:48
合計ジャッジ時間 8,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
57,676 KB
testcase_01 AC 115 ms
55,788 KB
testcase_02 AC 118 ms
55,896 KB
testcase_03 AC 164 ms
56,020 KB
testcase_04 AC 115 ms
55,804 KB
testcase_05 AC 127 ms
55,592 KB
testcase_06 AC 117 ms
55,480 KB
testcase_07 AC 125 ms
56,016 KB
testcase_08 AC 114 ms
56,092 KB
testcase_09 AC 119 ms
54,320 KB
testcase_10 AC 112 ms
55,400 KB
testcase_11 AC 179 ms
58,044 KB
testcase_12 AC 182 ms
56,716 KB
testcase_13 AC 133 ms
55,920 KB
testcase_14 AC 172 ms
56,076 KB
testcase_15 AC 173 ms
56,636 KB
testcase_16 AC 173 ms
57,812 KB
testcase_17 AC 180 ms
58,308 KB
testcase_18 AC 181 ms
57,908 KB
testcase_19 AC 178 ms
58,660 KB
testcase_20 AC 185 ms
58,304 KB
testcase_21 AC 178 ms
58,564 KB
testcase_22 AC 183 ms
58,328 KB
testcase_23 AC 182 ms
57,988 KB
testcase_24 AC 174 ms
58,672 KB
testcase_25 AC 184 ms
58,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final String YES = "YES";

    private static final String NO = "NO";

    private static int n;

    private static int m;

    private static int[] blocksCount;

    private static List<int[]> blocks;

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        n = Integer.parseInt(cin.next());
        m = Integer.parseInt(cin.next());
        blocksCount = new int[(m + 1) / 2];
        blocks = new ArrayList<int[]>(n);
        for (int i = 0; i < n; i++) {
            int[] block = new int[2];
            int begin = Integer.parseInt(cin.next());
            int end = Integer.parseInt(cin.next());
            block[0] = end - begin + 1;
            /* 180度回転したほうが開始位置が左にくるようであればその向きにしてからリストに詰める */
            block[1] = Math.min(begin, m - end - 1);
            blocks.add(block);
        }
        cin.close();
        /* リストをソートする。1.ブロック数の多いもの 2. */
        Collections.sort(blocks, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                return o2[0] == o1[0] ? o1[1] - o2[1] : o2[0] - o1[0];
            }
        });
        execute2();
    }

    private static void execute2() {
        for (int[] block : blocks) {
            for (int i = 0; i < block[0]; i++) {
                int index = block[1] + i;
                if (index >= m / 2) {
                    index = m - index - 1;
                }
                if (blocksCount[index] == 2) {
                    System.out.println(NO);
                    System.exit(0);
                } else if (index == m / 2 && blocksCount[index] == 1) {
                    System.out.println(NO);
                    System.exit(0);
                }
                blocksCount[index]++;
            }
        }
        System.out.println(YES);
    }
}
0