結果

問題 No.139 交差点
ユーザー takuktakuk
提出日時 2015-02-01 19:32:18
言語 Ruby
(3.3.0)
結果
AC  
実行時間 127 ms / 5,000 ms
コード長 596 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 11,252 KB
実行使用メモリ 21,032 KB
最終ジャッジ日時 2023-09-05 09:33:02
合計ジャッジ時間 4,494 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,168 KB
testcase_01 AC 76 ms
15,144 KB
testcase_02 AC 77 ms
15,132 KB
testcase_03 AC 79 ms
15,688 KB
testcase_04 AC 94 ms
18,112 KB
testcase_05 AC 77 ms
15,516 KB
testcase_06 AC 101 ms
18,216 KB
testcase_07 AC 80 ms
15,616 KB
testcase_08 AC 94 ms
18,116 KB
testcase_09 AC 80 ms
15,360 KB
testcase_10 AC 88 ms
16,700 KB
testcase_11 AC 103 ms
18,176 KB
testcase_12 AC 96 ms
18,048 KB
testcase_13 AC 78 ms
15,160 KB
testcase_14 AC 78 ms
15,184 KB
testcase_15 AC 77 ms
15,084 KB
testcase_16 AC 77 ms
15,144 KB
testcase_17 AC 76 ms
15,344 KB
testcase_18 AC 99 ms
18,200 KB
testcase_19 AC 82 ms
15,924 KB
testcase_20 AC 87 ms
16,764 KB
testcase_21 AC 126 ms
21,028 KB
testcase_22 AC 126 ms
21,032 KB
testcase_23 AC 127 ms
20,812 KB
testcase_24 AC 77 ms
15,304 KB
testcase_25 AC 80 ms
15,364 KB
testcase_26 AC 79 ms
15,180 KB
testcase_27 AC 80 ms
15,304 KB
testcase_28 AC 78 ms
15,164 KB
testcase_29 AC 81 ms
15,444 KB
testcase_30 AC 81 ms
15,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n, l = gets.split.map(&:to_i)
x = n.times.map{gets.split.map(&:to_i)}
r = Array.new(l,0)
w = Hash.new
x.each do |xx|
    xx[1].times do |i|
        r[xx[0] + i] = xx[2]
        w[xx[0] + i] = xx[1] - i
    end
end
wait = 0
i = 0
while i < l
    if r[i] == 0
        i += 1
        next
    end
    if ((i + wait) / r[i]) % 2 == 1 #red
        #puts "NOW RED"
        wait += r[i] - (i + wait) % r[i]
    elsif r[i] - (i + wait) % r[i] < w[i] #green but not enough time
        #puts "NOW GREEN BUT NOT ENOUGH TIME"
        wait += 2 * r[i] - (i + wait) % r[i]
    end
    i += 1
end
puts l + wait
0