結果
問題 |
No.67 よくある棒を切る問題 (1)
|
ユーザー |
![]() |
提出日時 | 2018-06-16 18:16:36 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,031 bytes |
コンパイル時間 | 2,532 ms |
コンパイル使用メモリ | 85,624 KB |
実行使用メモリ | 72,160 KB |
最終ジャッジ日時 | 2025-03-03 11:17:34 |
合計ジャッジ時間 | 29,214 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 WA * 16 |
ソースコード
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 int calc(double cutwidth,long[] L) { int 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; } } }