結果
問題 | No.67 よくある棒を切る問題 (1) |
ユーザー |
|
提出日時 | 2019-04-06 00:13:09 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 1,050 ms / 5,000 ms |
コード長 | 1,303 bytes |
コンパイル時間 | 2,453 ms |
コンパイル使用メモリ | 80,400 KB |
実行使用メモリ | 72,392 KB |
最終ジャッジ日時 | 2025-03-03 11:24:16 |
合計ジャッジ時間 | 29,255 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] l = new long[n]; long max = 0; for (int i = 0; i < n; i++) { l[i] = sc.nextLong(); max = Math.max(max, l[i]); } long k = sc.nextLong(); // System.out.println(Arrays.toString(l)); double ans = binSearch(0, (double) max + 1, k, l, n); // System.out.println(ans); System.out.printf("%.12f%n", ans); } public static double binSearch(double ok, double ng, long k, long[] l, int n) { for (int i = 0; i < 100; i++) { double mid = (ok + ng) / 2.0; // System.out.printf("ok = %f%n", ok); // System.out.printf("ng = %f%n", ng); // System.out.printf("mid = %f%n", mid); if (solve(mid, k, l, n)) { ok = mid; } else { ng = mid; } } return ok; } public static boolean solve(double x, long k, long[] l, int n) { long cnt = 0; for (int i = 0; i < n; i++) { cnt += l[i] / x; } if (cnt < k) { return false; } return true; } }