結果

問題 No.27 板の準備
ユーザー tentententen
提出日時 2021-12-02 15:38:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 76 ms / 5,000 ms
コード長 2,026 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 74,316 KB
実行使用メモリ 53,512 KB
最終ジャッジ日時 2023-09-18 10:18:32
合計ジャッジ時間 5,180 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
51,492 KB
testcase_01 AC 59 ms
51,648 KB
testcase_02 AC 62 ms
51,312 KB
testcase_03 AC 64 ms
51,548 KB
testcase_04 AC 61 ms
51,820 KB
testcase_05 AC 61 ms
51,584 KB
testcase_06 AC 61 ms
49,428 KB
testcase_07 AC 74 ms
51,480 KB
testcase_08 AC 72 ms
51,552 KB
testcase_09 AC 61 ms
51,500 KB
testcase_10 AC 61 ms
51,468 KB
testcase_11 AC 63 ms
51,404 KB
testcase_12 AC 72 ms
51,364 KB
testcase_13 AC 60 ms
51,368 KB
testcase_14 AC 63 ms
51,832 KB
testcase_15 AC 61 ms
51,504 KB
testcase_16 AC 59 ms
51,480 KB
testcase_17 AC 66 ms
53,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int[] value = new int[4];
        for (int i = 0; i < 4; i++) {
            value[i] = sc.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int a = 30; a >= 3; a--) {
            for (int b = a - 1; b >= 2; b--) {
                for (int c = b - 1; c >= 1; c--) {
                    int[] counts = new int[31];
                    Arrays.fill(counts, Integer.MAX_VALUE / 10);
                    counts[0] = 0;
                    for (int i = 0; i + a <= 30; i++) {
                        counts[i + a] = Math.min(counts[i + a], counts[i] + 1);
                    }
                    for (int i = 0; i + b <= 30; i++) {
                        counts[i + b] = Math.min(counts[i + b], counts[i] + 1);
                    }
                    for (int i = 0; i + c <= 30; i++) {
                        counts[i + c] = Math.min(counts[i + c], counts[i] + 1);
                    }
                    int sum = 0;
                    for (int x : value) {
                        sum += counts[x];
                    }
                    min = Math.min(min, sum);
                }
            }
        }
        System.out.println(min);
    }
}
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 {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0