結果

問題 No.636 硬貨の枚数2
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-01-19 23:14:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 2,369 bytes
コンパイル時間 4,269 ms
コンパイル使用メモリ 74,432 KB
実行使用メモリ 51,836 KB
最終ジャッジ日時 2023-08-26 00:33:08
合計ジャッジ時間 8,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
49,492 KB
testcase_01 AC 44 ms
49,840 KB
testcase_02 AC 45 ms
49,768 KB
testcase_03 AC 46 ms
49,540 KB
testcase_04 AC 45 ms
49,628 KB
testcase_05 AC 45 ms
49,576 KB
testcase_06 AC 45 ms
49,912 KB
testcase_07 AC 45 ms
49,456 KB
testcase_08 AC 44 ms
49,540 KB
testcase_09 AC 45 ms
49,808 KB
testcase_10 AC 46 ms
49,672 KB
testcase_11 AC 45 ms
49,676 KB
testcase_12 AC 46 ms
49,660 KB
testcase_13 AC 46 ms
49,480 KB
testcase_14 AC 46 ms
49,464 KB
testcase_15 AC 45 ms
49,584 KB
testcase_16 AC 44 ms
49,568 KB
testcase_17 AC 45 ms
49,496 KB
testcase_18 AC 45 ms
49,492 KB
testcase_19 AC 45 ms
50,012 KB
testcase_20 AC 45 ms
49,736 KB
testcase_21 AC 45 ms
49,684 KB
testcase_22 AC 46 ms
49,452 KB
testcase_23 AC 44 ms
49,452 KB
testcase_24 AC 56 ms
50,544 KB
testcase_25 AC 64 ms
49,696 KB
testcase_26 AC 50 ms
49,920 KB
testcase_27 AC 58 ms
50,448 KB
testcase_28 AC 50 ms
49,668 KB
testcase_29 AC 61 ms
50,624 KB
testcase_30 AC 50 ms
49,500 KB
testcase_31 AC 58 ms
51,812 KB
testcase_32 AC 50 ms
49,496 KB
testcase_33 AC 48 ms
49,456 KB
testcase_34 AC 66 ms
51,560 KB
testcase_35 AC 66 ms
51,268 KB
testcase_36 AC 67 ms
51,480 KB
testcase_37 AC 66 ms
51,308 KB
testcase_38 AC 67 ms
51,512 KB
testcase_39 AC 66 ms
51,456 KB
testcase_40 AC 66 ms
51,384 KB
testcase_41 AC 66 ms
51,480 KB
testcase_42 AC 65 ms
51,612 KB
testcase_43 AC 66 ms
51,836 KB
testcase_44 AC 66 ms
51,788 KB
testcase_45 AC 66 ms
51,620 KB
testcase_46 AC 66 ms
51,500 KB
testcase_47 AC 66 ms
51,544 KB
testcase_48 AC 66 ms
51,316 KB
testcase_49 AC 66 ms
51,576 KB
testcase_50 AC 66 ms
51,504 KB
testcase_51 AC 66 ms
51,296 KB
testcase_52 AC 67 ms
51,484 KB
testcase_53 AC 66 ms
51,488 KB
testcase_54 AC 45 ms
49,460 KB
testcase_55 AC 45 ms
47,884 KB
testcase_56 AC 46 ms
49,484 KB
testcase_57 AC 45 ms
49,576 KB
testcase_58 AC 46 ms
49,916 KB
testcase_59 AC 45 ms
49,552 KB
testcase_60 AC 46 ms
49,492 KB
testcase_61 AC 46 ms
49,460 KB
testcase_62 AC 46 ms
49,572 KB
testcase_63 AC 45 ms
49,456 KB
testcase_64 AC 66 ms
51,756 KB
testcase_65 AC 67 ms
51,580 KB
testcase_66 AC 66 ms
51,576 KB
testcase_67 AC 66 ms
51,492 KB
testcase_68 AC 66 ms
51,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        String ns=sc.next();
        int m=ns.length();
        int[]a=new int[m+1];
        for(int i=1;i<=m;++i){
            a[i]=ns.charAt(i-1)-'0';
        }
        long[][]dp=new long[2][m+1];
        dp[0][0]=0;
        dp[1][0]=1;
        for(int i=0;i<m;++i){
            for(int b=0;b<2;++b){
                int w=a[i+1]+b;
                long ma=1L<<48;
                for(int j=0;j<10;++j){
                    int x=(j+w)/10;
                    int y=(j+w)%10;
                    int z=y%5;
                    y/=5;
                    int u=j/5;
                    int v=j%5;
                    ma=Math.min(ma,dp[x][i]+y+z+u+v);
                }
                dp[b][i+1]=ma;
            }
        }
        out.println(dp[0][m]);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        int[] nextIntArray(int n){
            int[]r=new int[n];
            for(int i=0;i<n;++i)r[i]=nextInt();
            return r;
        }
    }
}
0