結果

問題 No.126 2基のエレベータ
ユーザー papinianuspapinianus
提出日時 2017-02-01 12:05:13
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 619 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 18,372 KB
実行使用メモリ 18,948 KB
最終ジャッジ日時 2023-08-25 17:01:28
合計ジャッジ時間 1,872 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
18,784 KB
testcase_01 AC 15 ms
18,920 KB
testcase_02 WA -
testcase_03 AC 16 ms
18,852 KB
testcase_04 AC 15 ms
18,912 KB
testcase_05 AC 14 ms
18,876 KB
testcase_06 AC 15 ms
18,888 KB
testcase_07 AC 14 ms
18,808 KB
testcase_08 AC 15 ms
18,688 KB
testcase_09 AC 14 ms
18,788 KB
testcase_10 AC 15 ms
18,788 KB
testcase_11 AC 15 ms
18,816 KB
testcase_12 AC 14 ms
18,792 KB
testcase_13 AC 14 ms
18,860 KB
testcase_14 AC 16 ms
18,920 KB
testcase_15 AC 14 ms
18,784 KB
testcase_16 AC 14 ms
18,760 KB
testcase_17 AC 14 ms
18,920 KB
testcase_18 AC 15 ms
18,860 KB
testcase_19 AC 16 ms
18,916 KB
testcase_20 AC 15 ms
18,912 KB
testcase_21 AC 15 ms
18,844 KB
testcase_22 AC 15 ms
18,804 KB
testcase_23 AC 16 ms
18,920 KB
testcase_24 AC 15 ms
18,916 KB
testcase_25 AC 15 ms
18,804 KB
testcase_26 AC 15 ms
18,812 KB
testcase_27 AC 15 ms
18,884 KB
testcase_28 AC 15 ms
18,860 KB
testcase_29 AC 16 ms
18,808 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
list($a, $b, $s) = explode(" ", trim(fgets(STDIN)));

if(a_callable($a, $b, $s))
{
    echo cost($a, $s);
} else {
    $path1 = transit($b, $s, 1, $a);
    if($a != 0) {
        $path2 = transit($b, $s, $a, $a);
        $path1 = min($path1, $path2);
    }
    echo $path1;
}
echo PHP_EOL;

function a_callable($a, $b, $s) {
    $patha = abs($s - $a);
    $pathb = abs($s - $b);
    if($patha <= $pathb) {
        return true;
    }
    return false;
}

function cost($a, $s) {
    return abs($s - $a) + $s;
}

function transit($a, $s, $p, $p_prev) {
    return abs($s - $a) + abs($s - $p) + cost($p_prev, $p);
}

0