結果

問題 No.636 硬貨の枚数2
ユーザー tentententen
提出日時 2023-07-28 17:56:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 2,228 bytes
コンパイル時間 2,904 ms
コンパイル使用メモリ 85,008 KB
実行使用メモリ 37,528 KB
最終ジャッジ日時 2024-04-16 01:59:00
合計ジャッジ時間 8,572 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,720 KB
testcase_01 AC 52 ms
36,880 KB
testcase_02 AC 52 ms
37,276 KB
testcase_03 AC 53 ms
37,144 KB
testcase_04 AC 53 ms
36,824 KB
testcase_05 AC 53 ms
36,828 KB
testcase_06 AC 54 ms
36,608 KB
testcase_07 AC 53 ms
36,744 KB
testcase_08 AC 52 ms
37,268 KB
testcase_09 AC 52 ms
36,972 KB
testcase_10 AC 52 ms
37,056 KB
testcase_11 AC 53 ms
37,116 KB
testcase_12 AC 52 ms
37,044 KB
testcase_13 AC 52 ms
37,080 KB
testcase_14 AC 52 ms
37,160 KB
testcase_15 AC 51 ms
36,880 KB
testcase_16 AC 51 ms
37,160 KB
testcase_17 AC 53 ms
37,036 KB
testcase_18 AC 52 ms
37,156 KB
testcase_19 AC 52 ms
36,940 KB
testcase_20 AC 55 ms
37,184 KB
testcase_21 AC 52 ms
36,744 KB
testcase_22 AC 52 ms
37,052 KB
testcase_23 AC 55 ms
37,168 KB
testcase_24 AC 56 ms
37,368 KB
testcase_25 AC 57 ms
37,072 KB
testcase_26 AC 55 ms
36,840 KB
testcase_27 AC 54 ms
37,300 KB
testcase_28 AC 53 ms
37,208 KB
testcase_29 AC 57 ms
37,252 KB
testcase_30 AC 54 ms
37,224 KB
testcase_31 AC 56 ms
37,048 KB
testcase_32 AC 53 ms
36,904 KB
testcase_33 AC 53 ms
37,076 KB
testcase_34 AC 63 ms
37,356 KB
testcase_35 AC 59 ms
37,264 KB
testcase_36 AC 58 ms
37,380 KB
testcase_37 AC 59 ms
37,236 KB
testcase_38 AC 58 ms
37,392 KB
testcase_39 AC 59 ms
37,320 KB
testcase_40 AC 58 ms
37,144 KB
testcase_41 AC 59 ms
37,528 KB
testcase_42 AC 59 ms
37,420 KB
testcase_43 AC 59 ms
37,012 KB
testcase_44 AC 59 ms
37,216 KB
testcase_45 AC 61 ms
37,328 KB
testcase_46 AC 58 ms
37,220 KB
testcase_47 AC 59 ms
37,416 KB
testcase_48 AC 59 ms
37,140 KB
testcase_49 AC 58 ms
37,336 KB
testcase_50 AC 59 ms
37,144 KB
testcase_51 AC 60 ms
37,296 KB
testcase_52 AC 58 ms
37,376 KB
testcase_53 AC 58 ms
37,416 KB
testcase_54 AC 55 ms
36,840 KB
testcase_55 AC 54 ms
36,880 KB
testcase_56 AC 54 ms
37,240 KB
testcase_57 AC 53 ms
36,828 KB
testcase_58 AC 53 ms
37,116 KB
testcase_59 AC 53 ms
37,204 KB
testcase_60 AC 53 ms
37,060 KB
testcase_61 AC 52 ms
36,992 KB
testcase_62 AC 53 ms
36,908 KB
testcase_63 AC 54 ms
36,828 KB
testcase_64 AC 59 ms
37,392 KB
testcase_65 AC 62 ms
36,972 KB
testcase_66 AC 60 ms
37,424 KB
testcase_67 AC 58 ms
37,140 KB
testcase_68 AC 61 ms
37,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        char[] inputs = sc.next().toCharArray();
        int[] dp1 = new int[inputs.length * 2 + 2];
        int[] dp2 = new int[inputs.length * 2 + 2];
        dp2[0] = 2;
        for (int i = 0; i < inputs.length; i++) {
            int x = inputs[inputs.length - i - 1] - '0';
            int one = x % 5;
            int five = x / 5;
            dp1[i * 2 + 1] = Math.min(dp1[i * 2] + one, dp2[i * 2] + one + 1);
            dp2[i * 2 + 1] = Math.min(dp1[i * 2] + 5 - one, dp2[i * 2] + 5 - one - 1);
            dp1[i * 2 + 2] = Math.min(dp1[i * 2 + 1] + five, dp2[i * 2 + 1] + five + 1);
            dp2[i * 2 + 2] = Math.min(dp1[i * 2 + 1] + 2 - five, dp2[i * 2 + 1] + 2 - five - 1);
        }
        int ans = Math.min(dp1[inputs.length * 2], dp2[inputs.length * 2] + 1);
        System.out.println(ans);
    }
}
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