結果

問題 No.67 よくある棒を切る問題 (1)
ユーザー jp_stejp_ste
提出日時 2016-06-08 19:17:41
言語 Java21
(openjdk 21)
結果
AC  
実行時間 275 ms / 5,000 ms
コード長 3,438 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 77,788 KB
実行使用メモリ 56,272 KB
最終ジャッジ日時 2024-04-25 23:42:53
合計ジャッジ時間 10,928 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 262 ms
55,984 KB
testcase_01 AC 102 ms
52,628 KB
testcase_02 AC 191 ms
54,040 KB
testcase_03 AC 263 ms
56,032 KB
testcase_04 AC 238 ms
54,320 KB
testcase_05 AC 255 ms
56,092 KB
testcase_06 AC 244 ms
56,272 KB
testcase_07 AC 245 ms
54,448 KB
testcase_08 AC 275 ms
55,992 KB
testcase_09 AC 241 ms
54,356 KB
testcase_10 AC 220 ms
54,220 KB
testcase_11 AC 231 ms
56,024 KB
testcase_12 AC 215 ms
54,268 KB
testcase_13 AC 236 ms
54,236 KB
testcase_14 AC 264 ms
56,108 KB
testcase_15 AC 259 ms
56,104 KB
testcase_16 AC 258 ms
56,048 KB
testcase_17 AC 233 ms
54,200 KB
testcase_18 AC 262 ms
55,960 KB
testcase_19 AC 233 ms
54,424 KB
testcase_20 AC 271 ms
56,208 KB
testcase_21 AC 243 ms
54,524 KB
testcase_22 AC 221 ms
54,396 KB
testcase_23 AC 224 ms
54,400 KB
testcase_24 AC 126 ms
53,796 KB
testcase_25 AC 139 ms
54,128 KB
testcase_26 AC 130 ms
53,916 KB
testcase_27 AC 126 ms
54,168 KB
testcase_28 AC 182 ms
54,292 KB
testcase_29 AC 161 ms
54,156 KB
testcase_30 AC 139 ms
54,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
    static FastScanner scan = new FastScanner();
    static PrintWriter out = new PrintWriter(System.out);

    static int n;
    static int[] a;
    static long k;
    
    public static void main(String[] args) {
        n = scan.nextInt();
        a = new int[n];
        for(int i=0; i<n; i++) {
            a[i] = scan.nextInt();
        }
        k = scan.nextLong();
        
        double l = 0;
        double r = Integer.MAX_VALUE;
        for(int i=0; i<100; i++) {
            double m = (l+r)/2;
            if(comp(m)) {
                l = m;
            } else {
                r = m;
            }
        }
        System.out.printf("%.10f\n", l);
    }

    static boolean comp(double x) {
        long count = 0;
        for(int i=0; i<a.length; i++) {
            count += (long)(a[i] / x);
        }
        return count >= k;
    }
    
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            return (int)nextLong();
        }
        
        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}
0