結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー youthfuldays072youthfuldays072
提出日時 2018-06-16 18:19:08
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,211 ms / 5,000 ms
コード長 1,033 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 77,244 KB
実行使用メモリ 71,780 KB
最終ジャッジ日時 2024-04-26 00:34:08
合計ジャッジ時間 31,940 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,088 ms
70,776 KB
testcase_01 AC 141 ms
54,212 KB
testcase_02 AC 697 ms
60,604 KB
testcase_03 AC 986 ms
69,204 KB
testcase_04 AC 1,052 ms
71,652 KB
testcase_05 AC 1,092 ms
71,780 KB
testcase_06 AC 1,106 ms
71,556 KB
testcase_07 AC 1,076 ms
71,252 KB
testcase_08 AC 1,081 ms
71,176 KB
testcase_09 AC 1,155 ms
71,084 KB
testcase_10 AC 998 ms
71,512 KB
testcase_11 AC 1,050 ms
71,584 KB
testcase_12 AC 1,071 ms
71,240 KB
testcase_13 AC 1,106 ms
71,388 KB
testcase_14 AC 1,098 ms
70,856 KB
testcase_15 AC 1,048 ms
71,540 KB
testcase_16 AC 1,098 ms
71,528 KB
testcase_17 AC 1,105 ms
71,612 KB
testcase_18 AC 1,105 ms
71,612 KB
testcase_19 AC 1,176 ms
70,588 KB
testcase_20 AC 1,087 ms
71,524 KB
testcase_21 AC 1,211 ms
71,044 KB
testcase_22 AC 1,052 ms
71,080 KB
testcase_23 AC 1,098 ms
71,384 KB
testcase_24 AC 135 ms
53,888 KB
testcase_25 AC 237 ms
57,388 KB
testcase_26 AC 223 ms
56,832 KB
testcase_27 AC 199 ms
54,284 KB
testcase_28 AC 497 ms
59,212 KB
testcase_29 AC 363 ms
58,804 KB
testcase_30 AC 243 ms
57,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Main main=new Main();
		main.run();
	}

	void run() {


		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		long[] L=new long[N];

		long maxlength=-1;
		for(int i=0;i<N;i++) {

			long buf=sc.nextLong();
			L[i]=buf;

			if(maxlength<buf) {
				maxlength=buf;
			}
		}

		Long K=sc.nextLong();

		double l=0.0;
		double u=maxlength+1;
		double mid=0.0;

		for(int i=0;i<100;i++) {
			mid=(l+u)/2.0;

			if(judge(mid,L,K)) {
				l=mid;
			}else {
				u=mid;
			}
		}



		System.out.println(mid);




	}



	//ある幅で何本とれるか返す関数
	public static long calc(double cutwidth,long[] L) {

		long count=0;

		for(int i=0;i<L.length;i++) {
			count+=(int)L[i]/cutwidth;
		}


		return count;
	}

	//ある幅でK本以上とれるかどうか判定する関数。
	public static boolean judge(double cutwidth,long[] L,long K) {

		if(calc(cutwidth,L)>=K) {
			return true;
		}else {
			return false;
		}

	}




}

0