結果

問題 No.58 イカサマなサイコロ
ユーザー htensaihtensai
提出日時 2019-12-06 13:59:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 122 ms / 5,000 ms
コード長 949 bytes
コンパイル時間 2,982 ms
コンパイル使用メモリ 73,508 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2023-08-24 19:52:25
合計ジャッジ時間 4,074 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,960 KB
testcase_01 AC 119 ms
55,824 KB
testcase_02 AC 121 ms
55,656 KB
testcase_03 AC 121 ms
55,708 KB
testcase_04 AC 121 ms
56,152 KB
testcase_05 AC 121 ms
55,696 KB
testcase_06 AC 122 ms
55,956 KB
testcase_07 AC 121 ms
55,704 KB
testcase_08 AC 122 ms
55,708 KB
testcase_09 AC 118 ms
55,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		double[] rateA = new double[n * 6 + 1];
		double[] rateB = new double[n * 6 + 1];
		rateA[0] = 1;
		rateB[0] = 1;
		for (int i = 0; i < n; i++) {
		    double[] nextA = new double[n * 6 + 1];
		    double[] nextB = new double[n * 6 + 1];
		    for (int j = i; j < i * 6 + 1; j++) {
		        for (int a = 1; a <= 6; a++) {
		            nextA[j + a] += rateA[j] / 6;
		            if (i < k && a <= 3) {
		                nextB[j + a + 3] += rateB[j] / 6;
		            } else {
		                nextB[j + a] += rateB[j] / 6;
		            }
		        }
		    }
		    rateA = nextA;
		    rateB = nextB;
		}
		double rate = 0;
		for (int i = 1; i <= n * 6; i++) {
		    rateA[i] += rateA[i - 1];
		    rate += rateB[i] * rateA[i - 1];
		}
		System.out.println(rate);
   }
}

0