結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー fjafjafjafjafjafja
提出日時 2017-09-20 20:44:31
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 959 bytes
コンパイル時間 4,150 ms
コンパイル使用メモリ 78,060 KB
実行使用メモリ 76,736 KB
最終ジャッジ日時 2024-04-25 21:18:39
合計ジャッジ時間 26,364 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 901 ms
68,932 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 AC 1,000 ms
69,312 KB
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 1,082 ms
68,628 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 959 ms
69,288 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 972 ms
69,264 KB
testcase_16 TLE -
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.Scanner;

public class N067
{
	static double max=0,min=Math.pow(10, -9),ans,k;
	static int n;
	static int[] l;
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		n=sc.nextInt();

		l=new int[n];
		max=0;min=0;

		for(int i=0;i<n;i++)
		{
			l[i]=sc.nextInt();
			max=(l[i]>max)?l[i]:max;
		}
		k=sc.nextInt();

		if(isok(max))
		{
			System.out.println(max);
		}
		else
		{
			nibun(min,max);
			System.out.printf("%.8f",ans);
		}


	}

	static void nibun(double min,double max)
	{
		double av=(max+min)/2;
		double dif=max-min;
		if(dif<Math.pow(10, -8))
		{
			ans=av;
			return;
		}
		else
		{
			if(isok(av))
			{
				nibun(av,max);
			}
			else
			{
				nibun(min,av);
			}
		}
	}

	static boolean isok(double a)
	{
		int cnt=0;
		int end=0;
		for(int i=0;end==0&&i<n;i++)
		{
			cnt+=(int)(l[i]/a);
			if(cnt>=k)
			{end=1;}
		}
		if(end==1)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
0