結果
| 問題 | No.636 硬貨の枚数2 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2018-01-22 14:43:58 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 8 ms / 2,000 ms | 
| コード長 | 1,047 bytes | 
| コンパイル時間 | 628 ms | 
| コンパイル使用メモリ | 114,220 KB | 
| 実行使用メモリ | 6,948 KB | 
| 最終ジャッジ日時 | 2024-06-12 23:36:22 | 
| 合計ジャッジ時間 | 2,384 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 65 | 
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;
immutable int INF = 1 << 29;
void main() {
    auto N = readln.chomp.to!(dchar[]);
    N.reverse;
    N ~= '0';
    
    auto dp = new int[][](N.length+1, 2);
    foreach (i; 0..N.length+1) dp[i].fill(INF);
    dp[0][0] = 0;
    foreach (i; 0..N.length) {
        foreach (j; 0..2) {
            int d = N[i] - '0';
            int x = INF;
            int y = INF;
            foreach (a; 0..10) {
                foreach (b; 0..10) {
                    if ((a - b - j + 10) % 10 != d) continue;
                    int c = a / 5 + a % 5 + b / 5 + b % 5;
                    if (a - j >= b) x = min(x, c);
                    else            y = min(y, c);
                }
            }
            dp[i+1][0] = min(dp[i+1][0], dp[i][j] + x);
            dp[i+1][1] = min(dp[i+1][1], dp[i][j] + y);
        }
    }
    dp[N.length][0].writeln;
}
            
            
            
        