結果
| 問題 |
No.274 The Wall
|
| コンテスト | |
| ユーザー |
fal_rnd
|
| 提出日時 | 2016-10-29 18:12:29 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 286 ms / 2,000 ms |
| コード長 | 1,599 bytes |
| コンパイル時間 | 2,279 ms |
| コンパイル使用メモリ | 80,688 KB |
| 実行使用メモリ | 59,812 KB |
| 最終ジャッジ日時 | 2025-03-17 18:51:36 |
| 合計ジャッジ時間 | 8,862 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 23 |
ソースコード
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);
}
}
fal_rnd