結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー wdkkouwdkkou
提出日時 2019-04-06 00:13:09
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,137 ms / 5,000 ms
コード長 1,303 bytes
コンパイル時間 2,281 ms
コンパイル使用メモリ 77,468 KB
実行使用メモリ 71,876 KB
最終ジャッジ日時 2024-04-26 00:40:33
合計ジャッジ時間 31,835 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,100 ms
70,804 KB
testcase_01 AC 147 ms
54,156 KB
testcase_02 AC 706 ms
60,880 KB
testcase_03 AC 982 ms
69,160 KB
testcase_04 AC 1,137 ms
71,504 KB
testcase_05 AC 1,134 ms
71,292 KB
testcase_06 AC 1,121 ms
71,616 KB
testcase_07 AC 1,114 ms
70,536 KB
testcase_08 AC 1,117 ms
71,876 KB
testcase_09 AC 1,110 ms
70,836 KB
testcase_10 AC 1,052 ms
71,392 KB
testcase_11 AC 1,061 ms
71,316 KB
testcase_12 AC 1,076 ms
71,296 KB
testcase_13 AC 1,115 ms
71,368 KB
testcase_14 AC 1,088 ms
70,736 KB
testcase_15 AC 1,080 ms
71,356 KB
testcase_16 AC 1,116 ms
71,552 KB
testcase_17 AC 1,088 ms
71,480 KB
testcase_18 AC 1,134 ms
71,596 KB
testcase_19 AC 1,117 ms
70,932 KB
testcase_20 AC 1,082 ms
71,124 KB
testcase_21 AC 1,115 ms
71,116 KB
testcase_22 AC 1,070 ms
71,248 KB
testcase_23 AC 1,122 ms
71,136 KB
testcase_24 AC 136 ms
54,244 KB
testcase_25 AC 238 ms
57,404 KB
testcase_26 AC 214 ms
56,700 KB
testcase_27 AC 207 ms
54,760 KB
testcase_28 AC 497 ms
59,444 KB
testcase_29 AC 357 ms
58,904 KB
testcase_30 AC 235 ms
57,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
    }
}
0