結果

問題 No.58 イカサマなサイコロ
ユーザー misora192misora192
提出日時 2020-06-23 08:29:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,084 bytes
コンパイル時間 1,565 ms
コンパイル使用メモリ 166,108 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-16 19:44:50
合計ジャッジ時間 2,285 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

	double dp1[n+1][6*n+1], dp2[n+1][6*n+1];
	rep(i, n+1) rep(j, 6*n+1) {
		dp1[i][j] = 0.0;
		dp2[i][j] = 0.0;
	}

	dp1[0][0] = 1.0;
	dp2[0][0] = 1.0;
	rep(i, n) rep(j, 6*n+1){
		for(int l = 1; l <= 6; l++){
			if(j+l <= 6*n) dp1[i+1][j+l] += dp1[i][j] / 6.0;
		}

		if(i+1 <= k){
			for(int l = 4; l <= 6; l++){
				if(j+l <= 6*n) dp2[i+1][j+l] += 2.0 * dp2[i][j] / 6.0;
			}
		}else{
			for(int l = 1; l <= 6; l++){
				if(j+l <= 6*n) dp2[i+1][j+l] += dp2[i][j] / 6.0;
			}
		}
	}

	double ans = 0.0;
	rep(i, 6*n+1){
		for(int j = i + 1; j <= 6*n; j++) ans += dp1[n][i] * dp2[n][j];
	}
	
	cout << fixed << setprecision(10);
	cout << ans << endl;
}
0