結果

問題 No.242 ビンゴゲーム
ユーザー mobius_bkstmobius_bkst
提出日時 2015-07-11 11:35:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,221 bytes
コンパイル時間 3,316 ms
コンパイル使用メモリ 75,896 KB
実行使用メモリ 49,912 KB
最終ジャッジ日時 2023-09-22 11:06:42
合計ジャッジ時間 4,619 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,844 KB
testcase_01 AC 46 ms
49,656 KB
testcase_02 AC 46 ms
49,644 KB
testcase_03 AC 44 ms
49,636 KB
testcase_04 AC 44 ms
49,628 KB
testcase_05 AC 44 ms
49,528 KB
testcase_06 AC 44 ms
49,752 KB
testcase_07 AC 44 ms
49,496 KB
testcase_08 AC 46 ms
49,728 KB
testcase_09 AC 44 ms
49,596 KB
testcase_10 AC 46 ms
49,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class No242 {
    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    System.in));
            BigInteger N = new BigInteger(br.readLine());

            double numerator = combination(N, new BigInteger("5"))
                    .doubleValue();
            double denominator = combination(new BigInteger("99"),
                    new BigInteger("5")).doubleValue();

            System.out.println(numerator * 12 / denominator);

        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("Error:" + e.getMessage());
        }
    }

    static BigInteger combination(BigInteger n, BigInteger r) {

        if (n.compareTo(r) < 0) {
            return BigInteger.ZERO;
        }

        BigInteger n_r = n.subtract(r);

        BigInteger facN = factorial(n);
        BigInteger facN_R = factorial(n_r);
        BigInteger facR = factorial(r);

        return facN.divide(facN_R.multiply(facR));
    }

    static BigInteger factorial(BigInteger n) {
        BigInteger ans = BigInteger.ONE;
        for (long i = n.longValue(); i >= 1; i--) {
            ans = ans.multiply(BigInteger.valueOf(i));
        }
        return ans;
    }

    // static long combination(long n, long r) {
    //
    // if (n < r) {
    // return 0;
    // }
    //
    // long n_r = n - r;
    //
    // for (long i = n - 1; i >= 1; i--) {
    // n *= i;
    // }
    //
    // if (n == 0) {
    // n = 1;
    // }
    //
    // for (long i = n_r; i >= 1; i--) {
    // n_r *= i;
    // }
    //
    // if (n_r == 0) {
    // n_r = 1;
    // }
    //
    // for (long i = r - 1; i >= 1; i--) {
    // r *= i;
    // }
    //
    // if (r == 0) {
    // r = 1;
    // }
    //
    // return n / (n_r * r);
    // }

    static int[] strToIntArray(String S) {
        String[] strArray = S.split(" ");
        int[] intArray = new int[strArray.length];
        for (int i = 0; i < strArray.length; i++) {
            intArray[i] = Integer.parseInt(strArray[i]);
        }
        return intArray;
    }
}
0