結果

問題 No.636 硬貨の枚数2
ユーザー htensaihtensai
提出日時 2020-02-13 10:55:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,907 bytes
コンパイル時間 2,528 ms
コンパイル使用メモリ 77,936 KB
実行使用メモリ 56,692 KB
最終ジャッジ日時 2024-04-15 12:36:45
合計ジャッジ時間 14,979 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,520 KB
testcase_01 AC 139 ms
41,468 KB
testcase_02 AC 137 ms
41,636 KB
testcase_03 AC 136 ms
41,064 KB
testcase_04 AC 137 ms
41,408 KB
testcase_05 AC 136 ms
41,700 KB
testcase_06 AC 134 ms
41,316 KB
testcase_07 AC 136 ms
41,616 KB
testcase_08 WA -
testcase_09 AC 134 ms
41,896 KB
testcase_10 AC 132 ms
41,528 KB
testcase_11 AC 132 ms
41,904 KB
testcase_12 AC 135 ms
41,852 KB
testcase_13 AC 139 ms
41,652 KB
testcase_14 AC 138 ms
41,624 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 137 ms
41,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 157 ms
42,000 KB
testcase_45 AC 157 ms
42,696 KB
testcase_46 AC 153 ms
42,612 KB
testcase_47 AC 158 ms
42,404 KB
testcase_48 AC 154 ms
42,316 KB
testcase_49 AC 153 ms
42,384 KB
testcase_50 AC 155 ms
42,120 KB
testcase_51 AC 154 ms
42,096 KB
testcase_52 AC 156 ms
41,996 KB
testcase_53 AC 158 ms
42,080 KB
testcase_54 AC 154 ms
41,900 KB
testcase_55 AC 131 ms
41,660 KB
testcase_56 AC 134 ms
41,356 KB
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 134 ms
41,776 KB
testcase_60 AC 135 ms
41,400 KB
testcase_61 AC 135 ms
41,336 KB
testcase_62 AC 134 ms
41,620 KB
testcase_63 AC 136 ms
41,476 KB
testcase_64 AC 152 ms
42,020 KB
testcase_65 AC 155 ms
41,864 KB
testcase_66 AC 156 ms
42,368 KB
testcase_67 AC 159 ms
41,976 KB
testcase_68 AC 152 ms
41,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int length = arr.length + 2;
        int[] inputs = new int[length];
        for (int i = 1; i < length - 1; i++) {
            inputs[i] = arr[i - 1] - '0';
        }
        int[][] dp = new int[length][2];
        dp[0][0] = 0;
        dp[0][1] = Integer.MAX_VALUE / 10;
        for (int i = 1; i < length; i++) {
            int x = inputs[length - i - 1];
            dp[i][0] = Math.min(getCount(x) + dp[i - 1][0], getCount(x + 1) + dp[i - 1][1]);
            dp[i][1] = Math.min(getReturn(x) + dp[i - 1][0], getReturn(x + 1) + dp[i - 1][1]);
        }
        System.out.println(dp[length - 1][0]);
    }
    
    static int getCount(int x) {
        switch (x) {
            case 1:
                return 1;
            case 2:
                return 2;
            case 3:
                return 3;
            case 4:
                return 2;
            case 5:
                return 1;
            case 6:
                return 2;
            case 7:
                return 3;
            case 8:
                return 4;
            case 9:
                return 3;
            case 10:
                return 1;
        }
        return 0;
    }
    
    static int getReturn(int x) {
        switch (x) {
            case 1:
                return 5;
            case 2:
                return 4;
            case 3:
                return 3;
            case 4:
                return 2;
            case 5:
                return 1;
            case 6:
                return 2;
            case 7:
                return 3;
            case 8:
                return 2;
            case 9:
                return 1;
            case 10:
                return 0;
        }
        return 0;
    }
}
0