結果
問題 | No.139 交差点 |
ユーザー |
|
提出日時 | 2018-04-10 10:54:59 |
言語 | Ruby (3.4.1) |
結果 |
AC
|
実行時間 | 92 ms / 5,000 ms |
コード長 | 749 bytes |
コンパイル時間 | 147 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 12,416 KB |
最終ジャッジ日時 | 2024-06-26 20:52:51 |
合計ジャッジ時間 | 4,164 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
Syntax OK
ソースコード
# 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