結果

問題 No.636 硬貨の枚数2
ユーザー 37zigen37zigen
提出日時 2018-01-21 14:27:48
言語 Java21
(openjdk 21)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 2,201 ms
コンパイル使用メモリ 73,980 KB
実行使用メモリ 56,532 KB
最終ジャッジ日時 2023-08-26 19:36:00
合計ジャッジ時間 13,457 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,540 KB
testcase_01 AC 111 ms
55,812 KB
testcase_02 AC 113 ms
55,552 KB
testcase_03 AC 114 ms
56,264 KB
testcase_04 AC 115 ms
56,392 KB
testcase_05 AC 114 ms
55,788 KB
testcase_06 AC 113 ms
56,396 KB
testcase_07 AC 113 ms
55,860 KB
testcase_08 AC 114 ms
55,872 KB
testcase_09 AC 112 ms
55,984 KB
testcase_10 AC 114 ms
56,160 KB
testcase_11 AC 112 ms
55,616 KB
testcase_12 AC 113 ms
55,856 KB
testcase_13 AC 112 ms
56,412 KB
testcase_14 AC 116 ms
55,996 KB
testcase_15 AC 112 ms
56,432 KB
testcase_16 AC 112 ms
55,948 KB
testcase_17 AC 111 ms
56,244 KB
testcase_18 AC 113 ms
56,156 KB
testcase_19 AC 110 ms
55,692 KB
testcase_20 AC 110 ms
55,548 KB
testcase_21 AC 111 ms
55,664 KB
testcase_22 AC 106 ms
56,232 KB
testcase_23 AC 110 ms
56,128 KB
testcase_24 AC 133 ms
55,864 KB
testcase_25 AC 140 ms
55,564 KB
testcase_26 AC 121 ms
55,640 KB
testcase_27 AC 138 ms
55,988 KB
testcase_28 AC 121 ms
55,940 KB
testcase_29 AC 144 ms
53,828 KB
testcase_30 AC 116 ms
54,352 KB
testcase_31 AC 137 ms
56,100 KB
testcase_32 AC 120 ms
56,244 KB
testcase_33 AC 118 ms
55,328 KB
testcase_34 AC 142 ms
56,240 KB
testcase_35 AC 142 ms
56,000 KB
testcase_36 AC 141 ms
55,960 KB
testcase_37 AC 138 ms
56,084 KB
testcase_38 AC 142 ms
55,768 KB
testcase_39 AC 140 ms
56,132 KB
testcase_40 AC 141 ms
56,288 KB
testcase_41 AC 145 ms
55,612 KB
testcase_42 AC 143 ms
55,460 KB
testcase_43 AC 136 ms
55,580 KB
testcase_44 AC 143 ms
55,336 KB
testcase_45 AC 142 ms
55,344 KB
testcase_46 AC 142 ms
55,984 KB
testcase_47 AC 139 ms
56,148 KB
testcase_48 AC 142 ms
55,916 KB
testcase_49 AC 143 ms
56,348 KB
testcase_50 AC 143 ms
55,768 KB
testcase_51 AC 145 ms
55,560 KB
testcase_52 AC 145 ms
56,272 KB
testcase_53 AC 147 ms
56,136 KB
testcase_54 AC 114 ms
55,596 KB
testcase_55 AC 113 ms
56,056 KB
testcase_56 AC 111 ms
55,840 KB
testcase_57 AC 114 ms
55,856 KB
testcase_58 AC 113 ms
56,024 KB
testcase_59 AC 113 ms
55,744 KB
testcase_60 AC 112 ms
55,612 KB
testcase_61 AC 114 ms
55,772 KB
testcase_62 AC 113 ms
55,636 KB
testcase_63 AC 110 ms
55,892 KB
testcase_64 AC 144 ms
56,140 KB
testcase_65 AC 141 ms
56,532 KB
testcase_66 AC 142 ms
56,196 KB
testcase_67 AC 147 ms
56,328 KB
testcase_68 AC 142 ms
55,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	int[] p = { 0, 1, 2, 3, 4, 1, 2, 3, 4, 5 };

	public void run() {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		int n = str.length();
		int[][] a = new int[n + 2][2];
		for (int i = 0; i < a.length; ++i)
			for (int j = 0; j < a[i].length; ++j)
				a[i][j] = Integer.MAX_VALUE / 3;
		a[0][0] = 0;
		for (int i = 0; i <= n; ++i) {
			int v = i == n ? 0 : str.charAt(n - 1 - i) - '0';
			for (int j = 0; j <= 9; ++j) {
				for (int k = 0; k <= 1; ++k) {
					a[i + 1][(v + j + k) / 10] = Math.min(a[i + 1][(v + j + k) / 10],
							a[i][k] + p[(v + j + k) % 10] + p[j]);
				}
			}
		}
		System.out.println(a[n + 1][0]);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}
}
0