結果

問題 No.58 イカサマなサイコロ
ユーザー hotpepsihotpepsi
提出日時 2015-07-09 01:00:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,226 bytes
コンパイル時間 450 ms
コンパイル使用メモリ 62,712 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-22 09:39:29
合計ジャッジ時間 1,122 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <sstream>
#include <numeric>

using namespace std;

int main(int argc, char *argv[])
{
	cout.precision(12);
	int N, K;
	cin >> N >> K;

	int dp[2][2][80] = {};
	dp[0][0][0] = 1;
	for (int i = 1; i <= N; ++i) {
		int next = i & 1;
		int prev = next ^ 1;
		for (int j = 0; j <= 60; ++j) {
			dp[0][next][j] = 0;
		}
		for (int j = 0; j <= 60; ++j) {
			if (dp[0][prev][j]) {
				for (int k = 1; k <= 6; ++k) {
					dp[0][next][j + k] += dp[0][prev][j];
				}
			}
		}
	}

	dp[1][0][0] = 1;
	for (int i = 1; i <= N; ++i) {
		int next = i & 1;
		int prev = next ^ 1;
		for (int j = 0; j <= 60; ++j) {
			dp[1][next][j] = 0;
		}
		for (int j = 0; j <= 60; ++j) {
			if (dp[1][prev][j]) {
				if (i <= K) {
					for (int k = 0; k < 6; ++k) {
						dp[1][next][j + 4 + (k % 3)] += dp[1][prev][j];
					}
				} else {
					for (int k = 1; k <= 6; ++k) {
						dp[1][next][j + k] += dp[1][prev][j];
					}
				}
			}
		}
	}

	double ans = 0;
	double tot = accumulate(dp[0][N & 1], dp[0][N & 1] + 61, 0);
	for (int i = 2; i <= 60; ++i) {
		double win = accumulate(dp[0][N & 1], dp[0][N & 1] + i, 0);
		ans += (dp[1][N & 1][i] / tot) * (win / tot);
	}
	cout << ans << endl;
	return 0;
}
0