結果
問題 | No.636 硬貨の枚数2 |
ユーザー | tenten |
提出日時 | 2023-07-28 17:56:38 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 2,228 bytes |
コンパイル時間 | 2,723 ms |
コンパイル使用メモリ | 92,632 KB |
実行使用メモリ | 37,364 KB |
最終ジャッジ日時 | 2024-10-06 11:41:50 |
合計ジャッジ時間 | 8,036 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
36,584 KB |
testcase_01 | AC | 47 ms
37,036 KB |
testcase_02 | AC | 48 ms
36,956 KB |
testcase_03 | AC | 50 ms
37,052 KB |
testcase_04 | AC | 50 ms
37,016 KB |
testcase_05 | AC | 49 ms
36,780 KB |
testcase_06 | AC | 49 ms
36,872 KB |
testcase_07 | AC | 47 ms
36,760 KB |
testcase_08 | AC | 47 ms
36,720 KB |
testcase_09 | AC | 49 ms
36,980 KB |
testcase_10 | AC | 50 ms
37,168 KB |
testcase_11 | AC | 52 ms
37,016 KB |
testcase_12 | AC | 49 ms
36,780 KB |
testcase_13 | AC | 48 ms
36,788 KB |
testcase_14 | AC | 49 ms
36,824 KB |
testcase_15 | AC | 49 ms
36,888 KB |
testcase_16 | AC | 49 ms
36,688 KB |
testcase_17 | AC | 48 ms
37,144 KB |
testcase_18 | AC | 50 ms
36,904 KB |
testcase_19 | AC | 52 ms
36,820 KB |
testcase_20 | AC | 50 ms
36,764 KB |
testcase_21 | AC | 52 ms
36,844 KB |
testcase_22 | AC | 51 ms
36,704 KB |
testcase_23 | AC | 50 ms
37,108 KB |
testcase_24 | AC | 53 ms
36,904 KB |
testcase_25 | AC | 52 ms
37,144 KB |
testcase_26 | AC | 51 ms
37,028 KB |
testcase_27 | AC | 52 ms
36,812 KB |
testcase_28 | AC | 50 ms
37,092 KB |
testcase_29 | AC | 55 ms
36,988 KB |
testcase_30 | AC | 51 ms
36,468 KB |
testcase_31 | AC | 53 ms
37,040 KB |
testcase_32 | AC | 51 ms
37,092 KB |
testcase_33 | AC | 50 ms
37,096 KB |
testcase_34 | AC | 55 ms
37,036 KB |
testcase_35 | AC | 56 ms
37,272 KB |
testcase_36 | AC | 55 ms
37,148 KB |
testcase_37 | AC | 55 ms
37,060 KB |
testcase_38 | AC | 57 ms
37,192 KB |
testcase_39 | AC | 56 ms
37,224 KB |
testcase_40 | AC | 57 ms
37,364 KB |
testcase_41 | AC | 57 ms
37,000 KB |
testcase_42 | AC | 58 ms
37,108 KB |
testcase_43 | AC | 56 ms
37,092 KB |
testcase_44 | AC | 56 ms
36,708 KB |
testcase_45 | AC | 55 ms
36,936 KB |
testcase_46 | AC | 56 ms
37,096 KB |
testcase_47 | AC | 57 ms
37,324 KB |
testcase_48 | AC | 56 ms
37,176 KB |
testcase_49 | AC | 55 ms
37,200 KB |
testcase_50 | AC | 54 ms
37,148 KB |
testcase_51 | AC | 55 ms
36,812 KB |
testcase_52 | AC | 54 ms
37,016 KB |
testcase_53 | AC | 53 ms
37,228 KB |
testcase_54 | AC | 47 ms
36,856 KB |
testcase_55 | AC | 47 ms
36,716 KB |
testcase_56 | AC | 47 ms
36,544 KB |
testcase_57 | AC | 46 ms
36,984 KB |
testcase_58 | AC | 47 ms
36,480 KB |
testcase_59 | AC | 50 ms
36,844 KB |
testcase_60 | AC | 50 ms
36,920 KB |
testcase_61 | AC | 51 ms
36,892 KB |
testcase_62 | AC | 48 ms
36,972 KB |
testcase_63 | AC | 49 ms
37,032 KB |
testcase_64 | AC | 54 ms
36,776 KB |
testcase_65 | AC | 55 ms
37,164 KB |
testcase_66 | AC | 55 ms
37,112 KB |
testcase_67 | AC | 55 ms
37,112 KB |
testcase_68 | AC | 56 ms
37,036 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); int[] dp1 = new int[inputs.length * 2 + 2]; int[] dp2 = new int[inputs.length * 2 + 2]; dp2[0] = 2; for (int i = 0; i < inputs.length; i++) { int x = inputs[inputs.length - i - 1] - '0'; int one = x % 5; int five = x / 5; dp1[i * 2 + 1] = Math.min(dp1[i * 2] + one, dp2[i * 2] + one + 1); dp2[i * 2 + 1] = Math.min(dp1[i * 2] + 5 - one, dp2[i * 2] + 5 - one - 1); dp1[i * 2 + 2] = Math.min(dp1[i * 2 + 1] + five, dp2[i * 2 + 1] + five + 1); dp2[i * 2 + 2] = Math.min(dp1[i * 2 + 1] + 2 - five, dp2[i * 2 + 1] + 2 - five - 1); } int ans = Math.min(dp1[inputs.length * 2], dp2[inputs.length * 2] + 1); System.out.println(ans); } } class Utilities { static String arrayToLineString(Object[] arr) { return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n")); } static String arrayToLineString(int[] arr) { return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public int[] nextIntArray() throws Exception { return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray(); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }