結果
問題 | No.139 交差点 |
ユーザー |
|
提出日時 | 2016-10-19 12:38:55 |
言語 | PHP (843.2) |
結果 |
AC
|
実行時間 | 41 ms / 5,000 ms |
コード長 | 838 bytes |
コンパイル時間 | 2,651 ms |
コンパイル使用メモリ | 30,580 KB |
実行使用メモリ | 31,388 KB |
最終ジャッジ日時 | 2024-11-22 15:07:29 |
合計ジャッジ時間 | 5,055 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php $pos = 0; $now = 0; list($trafficCnt, $goal) = explode(" ",trim(fgets(STDIN))); for(;$trafficCnt;$trafficCnt--) { list($trafficStart, $trafficWidth, $trafficDuration) = explode(" ",trim(fgets(STDIN))); list($pos, $now) = arrive($pos, $trafficStart, $now); list($pos, $now) = accross($pos, $trafficWidth, $trafficDuration, $now); } if($pos < $goal) { list($pos, $now) = arrive($pos, $goal, $now); } echo $now.PHP_EOL; function arrive($from, $to, $now = 0) { $dist = $to - $from; return [$to, $now+$dist]; } function accross($from, $width, $duration, $now) { $trafficTime = $now % ($duration * 2); if($trafficTime + $width <= $duration) { return [$from + $width, $now + $width]; } else { return [$from + $width ,$now + ($duration * 2 - $trafficTime) + $width]; } }