結果

問題 No.58 イカサマなサイコロ
ユーザー jp_stejp_ste
提出日時 2014-11-10 16:21:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 115 ms / 5,000 ms
コード長 1,378 bytes
コンパイル時間 1,996 ms
コンパイル使用メモリ 74,312 KB
実行使用メモリ 55,860 KB
最終ジャッジ日時 2023-08-30 03:04:25
合計ジャッジ時間 3,912 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,644 KB
testcase_01 AC 111 ms
55,860 KB
testcase_02 AC 114 ms
55,424 KB
testcase_03 AC 114 ms
55,616 KB
testcase_04 AC 113 ms
55,364 KB
testcase_05 AC 113 ms
55,364 KB
testcase_06 AC 113 ms
55,832 KB
testcase_07 AC 115 ms
55,860 KB
testcase_08 AC 114 ms
55,848 KB
testcase_09 AC 115 ms
55,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	final static double NORMAL[] = {1,2,3,4,5,6};
	final static double CHEAT [] = {4,4,5,5,6,6};
	
	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(r.readLine());
		int k = Integer.parseInt(r.readLine());
		
		double tarou[][] = makeDpList(n, k);
		double jirou[][] = makeDpList(n, 0);
				
		double sum = 0d;
		for(int i=n; i<=6*n; i++) {
			for(int j=n; j<=6*n; j++) {
				if(i-j <= 0) break;
				sum += (tarou[i][n] * jirou[j][n]);
			}
		}
		System.out.println(String.format("%.5f", sum));
	}
	
	static double[][] makeDpList(int n, int k) {

		int nN = n - k;
		double list[][] = new double[n*6+1][n+1];
		
		if(nN > 0) {
			for(int i=1; i<=6; i++) list[i][1] = 1d/6;
		} else {
			for(int i=4; i<=6; i++) list[i][1] = 2d/6;
		}
		
		double d[];
		for(int j=2; j<=n; j++) {
			
			if(j<=nN) { d = NORMAL; }
			else 	  { d = CHEAT ; }
			
			int y = 6;
			for(int i=j; i<=j*6; i++) {
				for(int m=0; m<6; m++) {
					int rem = i-(int)d[m];
					if(rem < 0) continue;
					list[i][j] += list[rem][j-1];
				}
				if(list[i][j] > 0) list[i][j] /= y;
			}
			y *= 6;
		}	
		return list;
	}
}
0