結果

問題 No.126 2基のエレベータ
ユーザー thorikawathorikawa
提出日時 2015-05-16 20:45:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 982 bytes
コンパイル時間 2,982 ms
コンパイル使用メモリ 77,304 KB
実行使用メモリ 48,200 KB
最終ジャッジ日時 2024-04-19 01:44:40
合計ジャッジ時間 7,247 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
48,088 KB
testcase_01 AC 135 ms
48,032 KB
testcase_02 AC 140 ms
48,080 KB
testcase_03 AC 136 ms
48,048 KB
testcase_04 AC 138 ms
47,892 KB
testcase_05 AC 136 ms
48,076 KB
testcase_06 AC 137 ms
47,832 KB
testcase_07 AC 138 ms
48,176 KB
testcase_08 AC 137 ms
47,984 KB
testcase_09 AC 138 ms
47,688 KB
testcase_10 AC 135 ms
48,128 KB
testcase_11 AC 135 ms
47,876 KB
testcase_12 AC 134 ms
48,044 KB
testcase_13 AC 136 ms
47,788 KB
testcase_14 AC 121 ms
47,000 KB
testcase_15 AC 136 ms
47,964 KB
testcase_16 AC 136 ms
47,856 KB
testcase_17 AC 139 ms
47,984 KB
testcase_18 AC 141 ms
48,024 KB
testcase_19 AC 134 ms
47,988 KB
testcase_20 AC 138 ms
47,848 KB
testcase_21 AC 153 ms
48,172 KB
testcase_22 AC 137 ms
47,964 KB
testcase_23 AC 134 ms
47,800 KB
testcase_24 AC 135 ms
47,908 KB
testcase_25 AC 124 ms
46,536 KB
testcase_26 AC 139 ms
48,200 KB
testcase_27 AC 133 ms
48,072 KB
testcase_28 AC 136 ms
48,128 KB
testcase_29 AC 137 ms
47,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

/**
 * Created by poly on 11/29/14.
 */
public class Main {
    static int[][][] memo;

    static int solve(int a, int b, int s) {
        if (s == 1) {
            return Math.abs(a - 1) + 1;
        }
        if (Math.abs(a - s) <= Math.abs(b - s)) {
            return Math.abs(a - s) + s;
        }
        if (memo[a][b][s] > 0) {
            return memo[a][b][s];
        }
        int bmove = Math.abs(b - s);
        int ans = bmove + Math.abs(s - 1) + solve(a, 1, 1);
        if (a != 0) {
            ans = Math.min(ans, bmove + Math.abs(s - a) + solve(a, a, a));
        }
        memo[a][b][s] = ans;
        return ans;
    }

    public static void main(String[] argv) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int s = scanner.nextInt();
        memo = new int[101][101][101];
        int ans = solve(a, b, s);
        System.out.println(ans);
    }
}
0