結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー tentententen
提出日時 2023-01-26 11:58:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,756 ms / 5,000 ms
コード長 2,100 bytes
コンパイル時間 3,875 ms
コンパイル使用メモリ 82,316 KB
実行使用メモリ 64,184 KB
最終ジャッジ日時 2023-09-09 14:38:04
合計ジャッジ時間 42,521 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 332 ms
64,184 KB
testcase_01 AC 56 ms
51,300 KB
testcase_02 AC 779 ms
57,836 KB
testcase_03 AC 1,270 ms
58,508 KB
testcase_04 AC 1,590 ms
58,072 KB
testcase_05 AC 1,698 ms
62,140 KB
testcase_06 AC 1,692 ms
58,084 KB
testcase_07 AC 1,756 ms
63,692 KB
testcase_08 AC 1,711 ms
63,476 KB
testcase_09 AC 1,670 ms
62,236 KB
testcase_10 AC 1,463 ms
58,056 KB
testcase_11 AC 1,530 ms
58,160 KB
testcase_12 AC 1,411 ms
58,364 KB
testcase_13 AC 1,617 ms
62,008 KB
testcase_14 AC 1,700 ms
62,212 KB
testcase_15 AC 1,422 ms
59,188 KB
testcase_16 AC 1,728 ms
61,852 KB
testcase_17 AC 1,639 ms
58,252 KB
testcase_18 AC 1,714 ms
60,004 KB
testcase_19 AC 1,719 ms
64,120 KB
testcase_20 AC 1,653 ms
62,604 KB
testcase_21 AC 1,668 ms
63,520 KB
testcase_22 AC 1,444 ms
58,736 KB
testcase_23 AC 1,605 ms
59,872 KB
testcase_24 AC 44 ms
50,416 KB
testcase_25 AC 124 ms
52,876 KB
testcase_26 AC 92 ms
51,768 KB
testcase_27 AC 87 ms
52,048 KB
testcase_28 AC 439 ms
57,732 KB
testcase_29 AC 250 ms
53,984 KB
testcase_30 AC 126 ms
52,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int[] lengths = new int[n];
        for (int i = 0; i < n; i++) {
            lengths[i] = sc.nextInt();
        }
        long k = sc.nextLong();
        double left = 0;
        double right = Integer.MAX_VALUE;
        for (int i = 0; i < 1000; i++) {
            double m = (left + right) / 2;
            double sum = 0;
            for (int j = 0; j < n && sum <= k; j++) {
                sum += Math.floor(lengths[j] / m);
            }
            if (sum >= k) {
                left = m;
            } else {
                right = m;
            }
        }
        System.out.println(new java.math.BigDecimal(left).toPlainString());
    }
}

class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0