結果

問題 No.58 イカサマなサイコロ
ユーザー tentententen
提出日時 2020-11-17 12:34:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 5,000 ms
コード長 1,518 bytes
コンパイル時間 3,423 ms
コンパイル使用メモリ 73,840 KB
実行使用メモリ 56,232 KB
最終ジャッジ日時 2023-09-30 14:08:28
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,772 KB
testcase_01 AC 120 ms
55,944 KB
testcase_02 AC 117 ms
56,232 KB
testcase_03 AC 119 ms
56,100 KB
testcase_04 AC 118 ms
55,908 KB
testcase_05 AC 121 ms
56,092 KB
testcase_06 AC 121 ms
56,060 KB
testcase_07 AC 118 ms
55,988 KB
testcase_08 AC 117 ms
55,724 KB
testcase_09 AC 120 ms
55,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static HashSet<String> all = new HashSet<>();
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] ika = new int[]{3, 3, 4, 4, 5, 5};
        int[] base = new int[11];
        int[] next = new int[11];
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 6; j++) {
                base[j - i + 5]++;
            }
            for (int x : ika) {
                next[x - i + 5]++;
            }
        }
        double[][] probables = new double[n + 1][101];
        probables[0][50] = 1;
        for (int i = 1; i <= n; i++) {
            int[] tmp;
            if (i <= k) {
                tmp = next;
            } else {
                tmp = base;
            }
            for (int a = 0; a < probables[i].length; a++) {
                if (probables[i - 1][a] == 0.0) {
                    continue;
                } 
                for (int b = 0; b < tmp.length; b++) {
                    int idx = a + b - 5;
                    if (idx < 0 || idx >= probables[i].length || tmp[b] == 0) {
                        continue;
                    }
                    probables[i][idx] += probables[i - 1][a] * tmp[b] / 36;
                }
            }
        }
        double ans = 0;
        for (int i = 51; i < probables[n].length; i++) {
            ans += probables[n][i];
        }
        System.out.println(ans);
    }
}
0