結果

問題 No.636 硬貨の枚数2
ユーザー nebukuro09nebukuro09
提出日時 2018-01-22 13:52:04
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 1,045 bytes
コンパイル時間 804 ms
コンパイル使用メモリ 100,388 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 18:12:54
合計ジャッジ時間 4,020 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 WA -
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 WA -
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 8 ms
4,380 KB
testcase_45 AC 7 ms
4,380 KB
testcase_46 AC 7 ms
4,376 KB
testcase_47 AC 7 ms
4,376 KB
testcase_48 AC 7 ms
4,380 KB
testcase_49 AC 7 ms
4,376 KB
testcase_50 AC 7 ms
4,376 KB
testcase_51 AC 7 ms
4,376 KB
testcase_52 AC 7 ms
4,380 KB
testcase_53 AC 7 ms
4,376 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 AC 2 ms
4,376 KB
testcase_60 AC 2 ms
4,376 KB
testcase_61 AC 1 ms
4,380 KB
testcase_62 AC 1 ms
4,376 KB
testcase_63 AC 1 ms
4,376 KB
testcase_64 AC 7 ms
4,376 KB
testcase_65 WA -
testcase_66 AC 7 ms
4,376 KB
testcase_67 AC 7 ms
4,376 KB
testcase_68 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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' + j) % 10;
            int x = INF;
            int y = INF;
            foreach (a; 0..10) {
                foreach (b; 0..9) {
                    if ((a - b + 10) % 10 != d) continue;
                    int c = a / 5 + a % 5 + b / 5 + b % 5;
                    if (a >= 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;
}
0