結果

問題 No.27 板の準備
ユーザー GrenacheGrenache
提出日時 2016-03-12 11:48:35
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,294 bytes
コンパイル時間 3,626 ms
コンパイル使用メモリ 78,136 KB
実行使用メモリ 57,852 KB
最終ジャッジ日時 2023-10-25 08:00:53
合計ジャッジ時間 7,357 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 131 ms
57,500 KB
testcase_02 AC 135 ms
57,516 KB
testcase_03 AC 130 ms
55,760 KB
testcase_04 AC 135 ms
57,752 KB
testcase_05 AC 124 ms
56,428 KB
testcase_06 AC 135 ms
57,696 KB
testcase_07 AC 130 ms
57,596 KB
testcase_08 AC 138 ms
57,440 KB
testcase_09 AC 140 ms
57,660 KB
testcase_10 AC 135 ms
57,640 KB
testcase_11 AC 133 ms
57,740 KB
testcase_12 AC 134 ms
57,852 KB
testcase_13 AC 131 ms
57,620 KB
testcase_14 AC 128 ms
57,316 KB
testcase_15 AC 134 ms
57,632 KB
testcase_16 AC 131 ms
57,636 KB
testcase_17 AC 134 ms
57,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder27 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int[] v = new int[4];
        for (int i = 0; i < 4; i++) {
        	v[i] = sc.nextInt();
        }
        Arrays.sort(v);
        int max = v[3];

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < max; i++) {
            for (int j = i + 1; j < max; j++) {
            	next:
                for (int k = j + 1; k <= max; k++) {
                	int sum = 0;
                	for (int e : v) {
                		int tmp = isOK(e, i, j, k);
                		if (tmp == 0) {
                			continue next;
                		}
                		sum += tmp;
                	}
                	min = Math.min(min, sum);
                }
            }
        }

        System.out.println(min);

        sc.close();
    }

	private static int isOK(int v, int a, int b, int c) {
		int min = Integer.MAX_VALUE;
		for (int i = v / c; i >= 0; i--) {
			for (int j = (v - c * i) / b; j >= 0; j--) {
				if ((v - c * i - b * j) % a == 0) {
					min = Math.min(min, i + j + (v - c * i - b * j) / a);
				}
			}
		}

		if (min == Integer.MAX_VALUE) {
			return 0;
		} else {
			return min;
		}
	}
}
0