結果

問題 No.27 板の準備
ユーザー tentententen
提出日時 2021-11-10 09:38:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 2,020 bytes
コンパイル時間 3,548 ms
コンパイル使用メモリ 74,660 KB
実行使用メモリ 51,244 KB
最終ジャッジ日時 2023-08-13 01:49:38
合計ジャッジ時間 5,617 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
49,224 KB
testcase_01 AC 49 ms
49,584 KB
testcase_02 AC 55 ms
50,760 KB
testcase_03 AC 50 ms
49,548 KB
testcase_04 AC 55 ms
50,924 KB
testcase_05 AC 55 ms
50,704 KB
testcase_06 AC 56 ms
50,812 KB
testcase_07 AC 57 ms
50,816 KB
testcase_08 AC 57 ms
50,868 KB
testcase_09 AC 56 ms
50,780 KB
testcase_10 AC 56 ms
50,744 KB
testcase_11 AC 56 ms
50,884 KB
testcase_12 AC 56 ms
50,756 KB
testcase_13 AC 57 ms
50,896 KB
testcase_14 AC 55 ms
51,244 KB
testcase_15 AC 56 ms
51,004 KB
testcase_16 AC 56 ms
50,824 KB
testcase_17 AC 56 ms
50,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int[] ita = new int[4];
        for (int i = 0; i < 4; i++) {
            ita[i] = sc.nextInt();
        }
        int ans = Integer.MAX_VALUE;
        for (int i = 1; i <= 30; i++) {
            for (int j = i + 1; j <= 30; j++) {
                for (int k = j + 1; k <= 30; k++) {
                    int sum = 0;
                    int[] dp = new int[31];
                    int[] piece = new int[]{i, j, k};
                    for (int l = 0; l < 4; l++) {
                        sum += dfw(ita[l], piece, dp);
                    }
                    ans = Math.min(ans, sum);
                }
            }
        }
        System.out.println(ans);
    }
    
    static int dfw(int size, int[] piece, int[] dp) {
        if (size < 0) {
            return 40;
        }
        if (size == 0) {
            return 0;
        }
        if (dp[size] == 0) {
            dp[size] = Integer.MAX_VALUE;
            for (int x : piece) {
                dp[size] = Math.min(dp[size], dfw(size - x, piece, dp) + 1);
            }
        }
        return dp[size];
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    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 String nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0