結果
問題 | No.274 The Wall |
ユーザー | fal_rnd |
提出日時 | 2016-10-29 18:12:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 365 ms / 2,000 ms |
コード長 | 1,599 bytes |
コンパイル時間 | 2,421 ms |
コンパイル使用メモリ | 79,956 KB |
実行使用メモリ | 60,472 KB |
最終ジャッジ日時 | 2023-09-04 02:14:40 |
合計ジャッジ時間 | 9,864 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 129 ms
56,052 KB |
testcase_01 | AC | 131 ms
55,620 KB |
testcase_02 | AC | 129 ms
55,884 KB |
testcase_03 | AC | 208 ms
58,708 KB |
testcase_04 | AC | 128 ms
55,676 KB |
testcase_05 | AC | 128 ms
55,404 KB |
testcase_06 | AC | 127 ms
55,588 KB |
testcase_07 | AC | 129 ms
55,676 KB |
testcase_08 | AC | 128 ms
55,624 KB |
testcase_09 | AC | 133 ms
55,360 KB |
testcase_10 | AC | 130 ms
55,760 KB |
testcase_11 | AC | 303 ms
60,136 KB |
testcase_12 | AC | 301 ms
60,332 KB |
testcase_13 | AC | 182 ms
55,952 KB |
testcase_14 | AC | 260 ms
57,080 KB |
testcase_15 | AC | 317 ms
59,784 KB |
testcase_16 | AC | 297 ms
60,060 KB |
testcase_17 | AC | 279 ms
59,920 KB |
testcase_18 | AC | 281 ms
60,460 KB |
testcase_19 | AC | 357 ms
60,156 KB |
testcase_20 | AC | 351 ms
60,092 KB |
testcase_21 | AC | 349 ms
60,472 KB |
testcase_22 | AC | 309 ms
60,168 KB |
testcase_23 | AC | 323 ms
59,868 KB |
testcase_24 | AC | 306 ms
60,284 KB |
testcase_25 | AC | 365 ms
60,100 KB |
ソースコード
import java.util.*; class A{ static Scanner s = new Scanner(System.in); static boolean b[]; public static void main(String[] args) { Blocks[] blocks = new Blocks[s.nextInt()]; int m=s.nextInt(); b = new boolean[m]; for (int i=0; i<blocks.length; i++) { int pl=s.nextInt(), pr=s.nextInt(); Blocks b1 = new Blocks(m, pl, pr); blocks[i] = min(b1,b1.getReversedBlocks()); } Arrays.sort(blocks); for(Blocks bl:blocks) { if(checkPuttable(bl)) { put(bl); }else { Blocks b = bl.getReversedBlocks(); if(checkPuttable(b)){ put(b); }else { System.out.println("NO"); return; } } } System.out.println("YES"); } static boolean checkPuttable(Blocks blocks) { for(int i=blocks.pl; i<=blocks.pr; i++) { if(b[i]) return false; } return true; } static void put(Blocks blocks) { for(int i=blocks.pl; i<=blocks.pr; i++) { b[i]=true; } } static <T extends Comparable<T>> T min(T t1, T t2){ if(t1.compareTo(t2)<=0) return t1; else return t2; } } class Blocks implements Comparable<Blocks>{ int length,pl,pr; Blocks(int m, int pl, int pr) { this.length = m; this.pl = pl; this.pr = pr; } boolean isPainted(int i) { return (i>=this.pl)&&(i<=this.pr); } @Override public int compareTo(Blocks o) { for(int i=0; i<this.length; i++) { if(this.isPainted(i) != o.isPainted(i)) { if(this.isPainted(i)==false) return 1; else return -1; } } return 0; } Blocks getReversedBlocks() { return new Blocks(this.length, this.length-this.pr-1, this.length-this.pl-1); } }