結果

問題 No.27 板の準備
ユーザー tentententen
提出日時 2020-10-22 17:22:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 153 ms / 5,000 ms
コード長 1,429 bytes
コンパイル時間 4,073 ms
コンパイル使用メモリ 73,868 KB
実行使用メモリ 58,436 KB
最終ジャッジ日時 2023-09-28 14:43:23
合計ジャッジ時間 7,146 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
57,420 KB
testcase_01 AC 149 ms
57,892 KB
testcase_02 AC 150 ms
58,340 KB
testcase_03 AC 150 ms
58,092 KB
testcase_04 AC 151 ms
58,228 KB
testcase_05 AC 150 ms
58,000 KB
testcase_06 AC 153 ms
57,956 KB
testcase_07 AC 151 ms
58,416 KB
testcase_08 AC 152 ms
57,976 KB
testcase_09 AC 152 ms
58,284 KB
testcase_10 AC 152 ms
56,044 KB
testcase_11 AC 153 ms
58,040 KB
testcase_12 AC 153 ms
57,644 KB
testcase_13 AC 150 ms
57,992 KB
testcase_14 AC 152 ms
57,756 KB
testcase_15 AC 152 ms
57,984 KB
testcase_16 AC 153 ms
58,436 KB
testcase_17 AC 152 ms
58,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] boards = new int[4];
        for (int i = 0; i < 4; i++) {
            boards[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= 28; i++) {
            for (int j = i + 1; j <= 29; j++) {
                for (int k = j + 1; k <= 30; k++) {
                    int count = 0;
                    int[] values = new int[]{i, j, k};
                    for (int a = 0; a < 4; a++) {
                        int[][] dp = new int[3][boards[a] + 1];
                        count += dfw(2, boards[a], values, dp);
                        
                    }
                   min = Math.min(min, count);
                }
            }
        }
        System.out.println(min);
     }
     
     static int dfw(int idx, int length, int[] values, int[][] dp) {
         if (length == 0) {
             return 0;
         }
         if (idx < 0) {
             return Integer.MAX_VALUE / 10;
         }
         if (dp[idx][length] == 0) {
             dp[idx][length] = Integer.MAX_VALUE / 10;
             for (int i = 0; length >= i * values[idx]; i++) {
                 dp[idx][length] = Math.min(dp[idx][length], dfw(idx - 1, length - i * values[idx], values, dp) + i);
             }
         }
         return dp[idx][length];
     }
}
0