結果

問題 No.139 交差点
ユーザー YosukeKawadaYosukeKawada
提出日時 2018-04-10 10:54:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 84 ms / 5,000 ms
コード長 749 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 11,340 KB
実行使用メモリ 15,484 KB
最終ジャッジ日時 2023-09-09 03:44:40
合計ジャッジ時間 5,058 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,424 KB
testcase_01 AC 80 ms
15,420 KB
testcase_02 AC 80 ms
15,348 KB
testcase_03 AC 84 ms
15,248 KB
testcase_04 AC 82 ms
15,368 KB
testcase_05 AC 84 ms
15,416 KB
testcase_06 AC 82 ms
15,360 KB
testcase_07 AC 82 ms
15,264 KB
testcase_08 AC 81 ms
15,244 KB
testcase_09 AC 80 ms
15,264 KB
testcase_10 AC 82 ms
15,384 KB
testcase_11 AC 81 ms
15,192 KB
testcase_12 AC 83 ms
15,388 KB
testcase_13 AC 82 ms
15,408 KB
testcase_14 AC 81 ms
15,244 KB
testcase_15 AC 83 ms
15,200 KB
testcase_16 AC 80 ms
15,268 KB
testcase_17 AC 81 ms
15,156 KB
testcase_18 AC 81 ms
15,156 KB
testcase_19 AC 80 ms
15,416 KB
testcase_20 AC 81 ms
15,388 KB
testcase_21 AC 82 ms
15,384 KB
testcase_22 AC 82 ms
15,484 KB
testcase_23 AC 83 ms
15,276 KB
testcase_24 AC 80 ms
15,216 KB
testcase_25 AC 83 ms
15,424 KB
testcase_26 AC 83 ms
15,416 KB
testcase_27 AC 82 ms
15,236 KB
testcase_28 AC 83 ms
15,392 KB
testcase_29 AC 82 ms
15,164 KB
testcase_30 AC 84 ms
15,388 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

# coding: euc-jp
N,L = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }

Signals = (0...N).map{
  x,w,t = $stdin.gets.chomp.split(" ").map{ |a| a.to_i }
  { x: x, w: w, t: t }
}

x = 0
t = 0

Signals.each_with_index{ |s,i|
  t += s[:x] - x
  x = s[:x]
  
  isBlue = (t / s[:t]) % 2 == 0
  restTime = s[:t] - (t % s[:t])
  #p [i,x,t, isBlue, restTime]
  if isBlue
    if restTime >= s[:w]
      # 十分に余裕のある青信号 -> そのまま渡る
      #puts "B1"
      t += s[:w]
    else
      # 余裕のない青信号 -> 次の青まで待つ
      #puts "B2"
      t += restTime + s[:t] + s[:w]
    end
    # 赤信号 -> 次の青まで待つ
  else
    #puts "R"
    t += restTime + s[:w]
  end
  x = s[:x] + s[:w]
}

t += L - x

puts t

0