結果

問題 No.636 硬貨の枚数2
ユーザー tentententen
提出日時 2023-06-09 17:00:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,407 bytes
コンパイル時間 7,361 ms
コンパイル使用メモリ 85,284 KB
実行使用メモリ 34,720 KB
最終ジャッジ日時 2023-08-30 10:07:26
合計ジャッジ時間 13,349 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
33,744 KB
testcase_01 AC 42 ms
33,448 KB
testcase_02 AC 42 ms
33,440 KB
testcase_03 AC 41 ms
33,472 KB
testcase_04 AC 45 ms
33,328 KB
testcase_05 AC 42 ms
33,748 KB
testcase_06 AC 40 ms
33,344 KB
testcase_07 AC 40 ms
33,692 KB
testcase_08 AC 39 ms
33,640 KB
testcase_09 AC 39 ms
33,384 KB
testcase_10 AC 39 ms
33,856 KB
testcase_11 AC 39 ms
33,464 KB
testcase_12 AC 39 ms
33,596 KB
testcase_13 AC 39 ms
33,856 KB
testcase_14 AC 39 ms
33,692 KB
testcase_15 AC 39 ms
33,464 KB
testcase_16 AC 39 ms
33,408 KB
testcase_17 AC 40 ms
33,400 KB
testcase_18 AC 40 ms
33,464 KB
testcase_19 AC 42 ms
33,400 KB
testcase_20 AC 39 ms
33,692 KB
testcase_21 AC 41 ms
33,424 KB
testcase_22 AC 39 ms
33,856 KB
testcase_23 AC 39 ms
33,748 KB
testcase_24 AC 44 ms
33,640 KB
testcase_25 AC 47 ms
33,904 KB
testcase_26 AC 42 ms
33,896 KB
testcase_27 AC 46 ms
33,964 KB
testcase_28 AC 43 ms
33,696 KB
testcase_29 AC 47 ms
33,888 KB
testcase_30 AC 41 ms
33,544 KB
testcase_31 AC 46 ms
34,128 KB
testcase_32 AC 42 ms
33,600 KB
testcase_33 AC 40 ms
33,496 KB
testcase_34 AC 51 ms
34,004 KB
testcase_35 AC 51 ms
34,720 KB
testcase_36 AC 50 ms
34,316 KB
testcase_37 AC 50 ms
34,088 KB
testcase_38 AC 49 ms
34,328 KB
testcase_39 AC 49 ms
34,156 KB
testcase_40 AC 50 ms
34,100 KB
testcase_41 AC 49 ms
34,440 KB
testcase_42 AC 48 ms
34,024 KB
testcase_43 AC 48 ms
34,084 KB
testcase_44 AC 49 ms
34,136 KB
testcase_45 AC 49 ms
34,344 KB
testcase_46 AC 48 ms
34,388 KB
testcase_47 AC 48 ms
34,440 KB
testcase_48 AC 48 ms
34,440 KB
testcase_49 AC 48 ms
34,148 KB
testcase_50 AC 50 ms
34,420 KB
testcase_51 AC 49 ms
34,120 KB
testcase_52 AC 49 ms
33,960 KB
testcase_53 AC 50 ms
34,656 KB
testcase_54 AC 41 ms
33,384 KB
testcase_55 AC 40 ms
33,480 KB
testcase_56 AC 41 ms
33,632 KB
testcase_57 AC 42 ms
33,860 KB
testcase_58 AC 40 ms
33,412 KB
testcase_59 AC 44 ms
33,744 KB
testcase_60 AC 41 ms
33,400 KB
testcase_61 AC 40 ms
33,356 KB
testcase_62 AC 39 ms
33,752 KB
testcase_63 AC 39 ms
33,312 KB
testcase_64 AC 51 ms
34,384 KB
testcase_65 AC 50 ms
34,436 KB
testcase_66 AC 49 ms
34,008 KB
testcase_67 AC 49 ms
34,380 KB
testcase_68 AC 48 ms
34,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    static int[][] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int length = inputs.length;
        int[] values = new int[length * 2];
        for (int i = 0; i < length; i++) {
            int x = inputs[i] - '0';
            values[i * 2] = x / 5;
            values[i * 2 + 1] = x % 5;
        }
        int[][] dp = new int[length * 2 + 2][2];
        dp[length * 2][1] = 1;
        for (int i = length * 2 - 1; i >= 0; i--) {
            if (i % 2 == 0) {
                dp[i][0] = Math.min(dp[i + 1][0] + values[i], dp[i + 1][1] + values[i] + 1);
                dp[i][1] = Math.min(dp[i + 1][0] + 2 - values[i], dp[i + 1][1] + 2 - (values[i] + 1));
            } else {
                dp[i][0] = Math.min(dp[i + 1][0] + values[i], dp[i + 1][1] + values[i] + 1);
                dp[i][1] = Math.min(dp[i + 1][0] + 5 - values[i], dp[i + 1][1] + 5 - (values[i] + 1));
            }
        }
        dp[0][1]++;
        System.out.println(Math.min(dp[0][1], dp[0][0]));
    }
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0