結果

問題 No.274 The Wall
ユーザー YosukeKawada
提出日時 2018-01-09 15:22:03
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 1,006 bytes
コンパイル時間 250 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 46,848 KB
最終ジャッジ日時 2024-12-23 14:24:06
合計ジャッジ時間 15,588 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12 WA * 9 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N,M = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }

lines = []
N.times {
  l,r = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }
  lines << [l,r]
}
#p lines

connection = (0...lines.size).map { |i|
  l0,r0 = *lines[i]
  vl0,vr0 = M-1-l0,M-1-r0
  (0...lines.size).map { |j|
    next nil if i == j
    l1,r1 = *lines[j]
    ok1 = (r0 < l1 || r1 < l0)
    ok2 = (vr0 < l1 || r1 < vl0)
    case
    when  ok1 && !ok2; +1
    when !ok1 &&  ok2; -1
    when  ok1 &&  ok2; nil
    when !ok1 && !ok2
      puts "NO"
      exit
    end
  }
}

#p connection

status = (0..N).map{ nil }

connection.each_with_index { |line,i|
  status[i] = status[i] || +1
  line.each_with_index{ |c,j|
    case
    when i == j; next
    when c == +1 && status[j] == nil; status[j] = +status[i]
    when c == +1 && status[j] != status[i]
      puts "NO"
      exit
    when c == -1 && status[j] == nil; status[j] = -status[i]
    when c == -1 && status[j] == status[i]
      puts "NO"
      exit
    end
  }
}

#p status

puts "YES"
0