結果

問題 No.139 交差点
ユーザー papinianuspapinianus
提出日時 2016-10-19 12:38:55
言語 PHP
(8.3.4)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 838 bytes
コンパイル時間 2,352 ms
コンパイル使用メモリ 30,952 KB
実行使用メモリ 31,400 KB
最終ジャッジ日時 2024-05-02 04:33:22
合計ジャッジ時間 2,844 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
30,964 KB
testcase_01 AC 43 ms
31,040 KB
testcase_02 AC 43 ms
30,948 KB
testcase_03 AC 42 ms
31,248 KB
testcase_04 AC 43 ms
30,760 KB
testcase_05 AC 47 ms
31,224 KB
testcase_06 AC 42 ms
31,380 KB
testcase_07 AC 43 ms
30,900 KB
testcase_08 AC 42 ms
31,276 KB
testcase_09 AC 43 ms
31,108 KB
testcase_10 AC 43 ms
31,264 KB
testcase_11 AC 43 ms
31,072 KB
testcase_12 AC 42 ms
31,272 KB
testcase_13 AC 42 ms
30,992 KB
testcase_14 AC 43 ms
31,088 KB
testcase_15 AC 42 ms
31,124 KB
testcase_16 AC 40 ms
31,120 KB
testcase_17 AC 43 ms
31,136 KB
testcase_18 AC 40 ms
30,924 KB
testcase_19 AC 40 ms
31,024 KB
testcase_20 AC 42 ms
31,200 KB
testcase_21 AC 42 ms
31,156 KB
testcase_22 AC 42 ms
30,828 KB
testcase_23 AC 42 ms
30,952 KB
testcase_24 AC 42 ms
31,252 KB
testcase_25 AC 41 ms
31,100 KB
testcase_26 AC 42 ms
31,088 KB
testcase_27 AC 42 ms
31,292 KB
testcase_28 AC 41 ms
31,064 KB
testcase_29 AC 42 ms
31,400 KB
testcase_30 AC 43 ms
30,848 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?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];
    }
}
0