結果

問題 No.58 イカサマなサイコロ
ユーザー uafr_csuafr_cs
提出日時 2015-06-04 21:01:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 5,000 ms
コード長 1,476 bytes
コンパイル時間 2,456 ms
コンパイル使用メモリ 74,236 KB
実行使用メモリ 55,996 KB
最終ジャッジ日時 2023-09-20 19:10:19
合計ジャッジ時間 4,506 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,912 KB
testcase_01 AC 126 ms
55,724 KB
testcase_02 AC 126 ms
55,944 KB
testcase_03 AC 125 ms
55,600 KB
testcase_04 AC 125 ms
55,664 KB
testcase_05 AC 126 ms
55,588 KB
testcase_06 AC 128 ms
55,644 KB
testcase_07 AC 127 ms
55,996 KB
testcase_08 AC 128 ms
55,748 KB
testcase_09 AC 128 ms
55,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;

public class Main {
	
	public static double[] DP(final int SIZE, double[] base, final int N, int[] dice){
		if(base == null){
			base = new double[SIZE + 1];
			base[0] = 1;
		}
		double[] next = new double[SIZE + 1];
		
		for(int i = 0; i < N; i++){
			Arrays.fill(next, 0);
			for(int current = 0; current <= SIZE; current++){
				for(final int d : dice){
					if(current + d > SIZE){ break; }
					
					next[current + d] += base[current] / 6.0;
				}
			}
			
			{
				double[] tmp = base;
				base = next;
				next = tmp;
			}
		}
		
		return base;
	}
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		
		final int SIZE = N * 6;
		
		
		double[] large_DP = DP(SIZE, DP(SIZE, null, N - K, new int[]{1, 2, 3, 4, 5, 6}), K, new int[]{4, 4, 5, 5, 6, 6});
		double[] normal_DP = DP(SIZE, null, N, new int[]{1, 2, 3, 4, 5, 6});
		
		//System.out.println(Arrays.toString(large_DP));
		double[] sum_large_DP = new double[SIZE + 1];
		for(int i = SIZE - 1; i >= 0; i--){
			sum_large_DP[i] += (sum_large_DP[i + 1] + large_DP[i + 1]);
		}
		//System.out.println(Arrays.toString(sum_large_DP));
		
		double answer = 0;
		for(int i = 0; i <= SIZE; i++){
			answer += normal_DP[i] * sum_large_DP[i];
		}
		
		System.out.printf("%.8f\n", answer);
		
		
	}
	
}
0