結果

問題 No.126 2基のエレベータ
ユーザー papinianuspapinianus
提出日時 2017-02-01 12:06:39
言語 PHP
(8.3.4)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 650 bytes
コンパイル時間 5,001 ms
コンパイル使用メモリ 32,016 KB
実行使用メモリ 31,348 KB
最終ジャッジ日時 2024-04-19 01:51:21
合計ジャッジ時間 3,997 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
30,872 KB
testcase_01 AC 36 ms
31,176 KB
testcase_02 AC 39 ms
31,092 KB
testcase_03 AC 40 ms
30,996 KB
testcase_04 AC 40 ms
30,940 KB
testcase_05 AC 40 ms
31,348 KB
testcase_06 AC 38 ms
31,100 KB
testcase_07 AC 38 ms
30,724 KB
testcase_08 AC 37 ms
30,844 KB
testcase_09 AC 36 ms
30,780 KB
testcase_10 AC 37 ms
31,032 KB
testcase_11 AC 36 ms
30,984 KB
testcase_12 AC 40 ms
31,076 KB
testcase_13 AC 40 ms
31,108 KB
testcase_14 AC 37 ms
31,228 KB
testcase_15 AC 35 ms
30,896 KB
testcase_16 AC 37 ms
30,952 KB
testcase_17 AC 36 ms
30,876 KB
testcase_18 AC 34 ms
31,264 KB
testcase_19 AC 34 ms
30,988 KB
testcase_20 AC 36 ms
31,064 KB
testcase_21 AC 38 ms
31,096 KB
testcase_22 AC 37 ms
31,252 KB
testcase_23 AC 35 ms
30,928 KB
testcase_24 AC 36 ms
31,096 KB
testcase_25 AC 40 ms
30,908 KB
testcase_26 AC 36 ms
30,912 KB
testcase_27 AC 39 ms
30,988 KB
testcase_28 AC 38 ms
31,112 KB
testcase_29 AC 39 ms
30,964 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) {
    if($s == 1) { return true; }
    $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