結果

問題 No.274 The Wall
ユーザー YosukeKawadaYosukeKawada
提出日時 2018-01-09 15:52:34
言語 Ruby
(3.3.0)
結果
AC  
実行時間 1,569 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 541 ms
コンパイル使用メモリ 11,384 KB
実行使用メモリ 50,124 KB
最終ジャッジ日時 2023-09-04 02:29:40
合計ジャッジ時間 15,286 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,252 KB
testcase_01 AC 77 ms
15,128 KB
testcase_02 AC 77 ms
15,104 KB
testcase_03 AC 80 ms
15,132 KB
testcase_04 AC 79 ms
15,116 KB
testcase_05 AC 77 ms
15,156 KB
testcase_06 AC 79 ms
15,248 KB
testcase_07 AC 79 ms
15,080 KB
testcase_08 AC 78 ms
15,260 KB
testcase_09 AC 77 ms
15,164 KB
testcase_10 AC 77 ms
14,984 KB
testcase_11 AC 81 ms
15,332 KB
testcase_12 AC 1,521 ms
49,824 KB
testcase_13 AC 92 ms
15,748 KB
testcase_14 AC 305 ms
21,488 KB
testcase_15 AC 669 ms
29,920 KB
testcase_16 AC 81 ms
15,224 KB
testcase_17 AC 81 ms
15,240 KB
testcase_18 AC 82 ms
15,392 KB
testcase_19 AC 1,222 ms
45,760 KB
testcase_20 AC 1,397 ms
48,468 KB
testcase_21 AC 1,451 ms
48,996 KB
testcase_22 AC 1,224 ms
50,052 KB
testcase_23 AC 1,251 ms
50,008 KB
testcase_24 AC 1,543 ms
50,124 KB
testcase_25 AC 1,569 ms
50,124 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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-r0,M-1-l0
  (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 }

def digger(i, expected = nil)
  if $status[i]
    if expected
      if expected != $status[i]
        puts "NO"
        exit
      end
    end
    return
  end

  $status[i] = expected || +1
  $connection[i].each_with_index { |c,j|
    next unless c
    digger(j,$status[i]*c)
  }
end

(0...N).each { |i|
  digger(i)
}

puts "YES"
0