結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー kano_townkano_town
提出日時 2014-11-20 14:05:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,015 bytes
コンパイル時間 3,298 ms
コンパイル使用メモリ 74,320 KB
実行使用メモリ 65,032 KB
最終ジャッジ日時 2023-08-30 21:55:14
合計ジャッジ時間 15,680 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Yukicoder67 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		int sum = 0;
		for (int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
			sum += l[i];
		}
		int k = sc.nextInt();
		Arrays.sort(l);
		
		double low = 0, high = (double) sum / (double) k, mid = 0;
		for (int i = 0; i < 100; i++) {
			long count = 0;
			mid = (high + low) / 2.0;
//			System.out.println("mid = " + mid);
			if (isEnable(l, 0, k, mid)) {
				low = mid;
			} else {
				high = mid;
			}

		}
		System.out.println(mid);
	}
	static boolean isEnable(int[] l, int index, int k, double mid){
		if (index == l.length) {
			return false;
		}
		for (int i = k; i > 0; i--) {
			if ((double) l[l.length - index - 1] / (double) i >= mid) {
				if (i == k)
					return true;
				else 
					return isEnable(l, index+1, k-i, mid);
			}
		}
		return false;
	}
}
0