結果

問題 No.27 板の準備
ユーザー tentententen
提出日時 2022-08-19 11:53:00
言語 Java21
(openjdk 21)
結果
AC  
実行時間 77 ms / 5,000 ms
コード長 2,038 bytes
コンパイル時間 2,246 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 38,584 KB
最終ジャッジ日時 2024-04-16 17:22:53
合計ジャッジ時間 4,386 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,412 KB
testcase_01 AC 58 ms
37,796 KB
testcase_02 AC 63 ms
37,908 KB
testcase_03 AC 58 ms
37,440 KB
testcase_04 AC 64 ms
37,896 KB
testcase_05 AC 64 ms
37,904 KB
testcase_06 AC 77 ms
38,508 KB
testcase_07 AC 67 ms
38,508 KB
testcase_08 AC 69 ms
38,584 KB
testcase_09 AC 68 ms
38,332 KB
testcase_10 AC 64 ms
37,588 KB
testcase_11 AC 63 ms
37,800 KB
testcase_12 AC 64 ms
37,552 KB
testcase_13 AC 74 ms
38,080 KB
testcase_14 AC 63 ms
37,636 KB
testcase_15 AC 77 ms
38,396 KB
testcase_16 AC 61 ms
37,964 KB
testcase_17 AC 77 ms
38,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int[] sheets = new int[4];
        for (int i = 0; i < 4; i++) {
            sheets[i] = sc.nextInt();
        }
        int[] blocks = new int[3];
        long ans = Long.MAX_VALUE;
        for (int a = 1; a <= 30; a++) {
            blocks[0] = a;
            for (int b = a + 1; b <= 30; b++) {
                blocks[1] = b;
                for (int c = b + 1; c <= 30; c++) {
                    blocks[2] = c;
                    long count = 0;
                    int[] dp = new int[31];
                    for (int i = 0; i < 4; i++) {
                        count += dfw(sheets[i], blocks, dp);
                    }
                    ans = Math.min(ans, count);
                }
            }
        }
        System.out.println(ans);
    }
    
    static int dfw(int x, int[] blocks, int[] dp) {
        if (x < 0) {
            return Integer.MAX_VALUE / 2;
        }
        if (x == 0) {
            return 0;
        }
        if (dp[x] == 0) {
            dp[x] = Integer.MAX_VALUE / 2;
            for (int i = 0; i < 3; i++) {
                dp[x] = Math.min(dp[x], dfw(x - blocks[i], blocks, dp) + 1);
            }
        }
        return dp[x];
    }
}

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 next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0