結果
問題 | No.636 硬貨の枚数2 |
ユーザー | tenten |
提出日時 | 2023-06-09 17:00:57 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 2,407 bytes |
コンパイル時間 | 3,109 ms |
コンパイル使用メモリ | 85,228 KB |
実行使用メモリ | 51,560 KB |
最終ジャッジ日時 | 2025-01-01 21:29:22 |
合計ジャッジ時間 | 9,064 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
51,244 KB |
testcase_01 | AC | 56 ms
51,092 KB |
testcase_02 | AC | 50 ms
51,196 KB |
testcase_03 | AC | 49 ms
51,148 KB |
testcase_04 | AC | 48 ms
51,424 KB |
testcase_05 | AC | 47 ms
51,336 KB |
testcase_06 | AC | 46 ms
51,200 KB |
testcase_07 | AC | 55 ms
51,200 KB |
testcase_08 | AC | 48 ms
51,204 KB |
testcase_09 | AC | 48 ms
51,228 KB |
testcase_10 | AC | 46 ms
51,340 KB |
testcase_11 | AC | 50 ms
51,308 KB |
testcase_12 | AC | 51 ms
51,344 KB |
testcase_13 | AC | 50 ms
51,140 KB |
testcase_14 | AC | 52 ms
51,152 KB |
testcase_15 | AC | 51 ms
51,316 KB |
testcase_16 | AC | 49 ms
51,320 KB |
testcase_17 | AC | 48 ms
51,180 KB |
testcase_18 | AC | 50 ms
51,100 KB |
testcase_19 | AC | 48 ms
51,096 KB |
testcase_20 | AC | 48 ms
51,204 KB |
testcase_21 | AC | 48 ms
51,132 KB |
testcase_22 | AC | 48 ms
51,204 KB |
testcase_23 | AC | 49 ms
51,044 KB |
testcase_24 | AC | 51 ms
51,360 KB |
testcase_25 | AC | 55 ms
51,160 KB |
testcase_26 | AC | 49 ms
51,276 KB |
testcase_27 | AC | 57 ms
51,228 KB |
testcase_28 | AC | 50 ms
51,316 KB |
testcase_29 | AC | 58 ms
51,196 KB |
testcase_30 | AC | 55 ms
51,244 KB |
testcase_31 | AC | 51 ms
51,316 KB |
testcase_32 | AC | 51 ms
51,108 KB |
testcase_33 | AC | 52 ms
51,304 KB |
testcase_34 | AC | 59 ms
51,344 KB |
testcase_35 | AC | 61 ms
51,328 KB |
testcase_36 | AC | 56 ms
51,268 KB |
testcase_37 | AC | 60 ms
51,380 KB |
testcase_38 | AC | 59 ms
51,504 KB |
testcase_39 | AC | 58 ms
51,088 KB |
testcase_40 | AC | 58 ms
51,372 KB |
testcase_41 | AC | 57 ms
51,348 KB |
testcase_42 | AC | 57 ms
51,560 KB |
testcase_43 | AC | 55 ms
51,112 KB |
testcase_44 | AC | 57 ms
51,336 KB |
testcase_45 | AC | 58 ms
51,152 KB |
testcase_46 | AC | 56 ms
51,300 KB |
testcase_47 | AC | 57 ms
51,352 KB |
testcase_48 | AC | 55 ms
51,204 KB |
testcase_49 | AC | 55 ms
51,548 KB |
testcase_50 | AC | 57 ms
51,124 KB |
testcase_51 | AC | 57 ms
51,300 KB |
testcase_52 | AC | 56 ms
51,336 KB |
testcase_53 | AC | 59 ms
51,256 KB |
testcase_54 | AC | 49 ms
51,260 KB |
testcase_55 | AC | 48 ms
51,176 KB |
testcase_56 | AC | 49 ms
51,316 KB |
testcase_57 | AC | 52 ms
51,240 KB |
testcase_58 | AC | 52 ms
51,104 KB |
testcase_59 | AC | 53 ms
51,324 KB |
testcase_60 | AC | 53 ms
51,072 KB |
testcase_61 | AC | 50 ms
51,248 KB |
testcase_62 | AC | 48 ms
51,280 KB |
testcase_63 | AC | 51 ms
51,372 KB |
testcase_64 | AC | 61 ms
51,368 KB |
testcase_65 | AC | 62 ms
51,320 KB |
testcase_66 | AC | 64 ms
51,472 KB |
testcase_67 | AC | 63 ms
51,380 KB |
testcase_68 | AC | 60 ms
51,244 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.stream.*; public class Main { static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); char[] inputs = sc.next().toCharArray(); int length = inputs.length; int[] values = new int[length * 2]; for (int i = 0; i < length; i++) { int x = inputs[i] - '0'; values[i * 2] = x / 5; values[i * 2 + 1] = x % 5; } int[][] dp = new int[length * 2 + 2][2]; dp[length * 2][1] = 1; for (int i = length * 2 - 1; i >= 0; i--) { if (i % 2 == 0) { dp[i][0] = Math.min(dp[i + 1][0] + values[i], dp[i + 1][1] + values[i] + 1); dp[i][1] = Math.min(dp[i + 1][0] + 2 - values[i], dp[i + 1][1] + 2 - (values[i] + 1)); } else { dp[i][0] = Math.min(dp[i + 1][0] + values[i], dp[i + 1][1] + values[i] + 1); dp[i][1] = Math.min(dp[i + 1][0] + 5 - values[i], dp[i + 1][1] + 5 - (values[i] + 1)); } } dp[0][1]++; System.out.println(Math.min(dp[0][1], dp[0][0])); } } 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(); } }