結果
| 問題 | No.636 硬貨の枚数2 | 
| コンテスト | |
| ユーザー |  夕叢霧香(ゆうむらきりか) | 
| 提出日時 | 2018-01-19 23:14:53 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 98 ms / 2,000 ms | 
| コード長 | 2,369 bytes | 
| コンパイル時間 | 2,612 ms | 
| コンパイル使用メモリ | 77,812 KB | 
| 実行使用メモリ | 38,628 KB | 
| 最終ジャッジ日時 | 2024-12-24 12:52:11 | 
| 合計ジャッジ時間 | 9,327 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 65 | 
ソースコード
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;
        }
    }
}
            
            
            
        