結果

問題 No.450 ベー君のシャトルラン
ユーザー takepantakepan
提出日時 2016-12-22 12:54:43
言語 PHP
(8.3.4)
結果
TLE  
実行時間 -
コード長 1,121 bytes
コンパイル時間 1,004 ms
コンパイル使用メモリ 18,660 KB
実行使用メモリ 23,512 KB
最終ジャッジ日時 2023-08-21 05:26:43
合計ジャッジ時間 5,248 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
23,332 KB
testcase_01 AC 15 ms
18,964 KB
testcase_02 AC 15 ms
18,904 KB
testcase_03 AC 15 ms
18,920 KB
testcase_04 AC 15 ms
18,992 KB
testcase_05 AC 15 ms
18,932 KB
testcase_06 AC 15 ms
18,784 KB
testcase_07 AC 16 ms
18,848 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
    fscanf (STDIN, "%d %d", $vl, $vr);
    fscanf (STDIN, "%d", $d);
    fscanf (STDIN, "%d", $w);

    $t = 0;
    $pl = 0;    // 左車の位置
    $pr = $d;   // 右車の位置
    $pw = 0;    // ハチの位置
    $di = "r";    // 向き
    $ans = 0;
    $prev = 0;

    while ($pr - $pl > 0) {
        switch ($di) {
            // 右向き
            case "r":
                $dt = ($pr - $pw) / ($vr + $w);
                $pw += $dt * $w;
                $pr -= $dt * $vr;
                $pl += $dt * $vl;
                $ans += $dt * $w;
                $di = "l";
                break;

            // 左向き
            case "l":
                $dt = ($pw - $pl) / ($vl + $w);
                $pw -= $dt * $w;
                $pr -= $dt * $vr;
                $pl += $dt * $vl;
                $ans += $dt * $w;
                $di = "r";
                break;
        }

        // 答えが増えなくなったら終了
        if ($prev == $ans) break;
        $prev = $ans;

        // 確認用
        // echo $pl . " " . $pr . " " . $ans . PHP_EOL;
    }

    echo $ans . PHP_EOL;
0