結果

問題 No.58 イカサマなサイコロ
ユーザー なおなお
提出日時 2014-10-17 23:11:01
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,149 bytes
コンパイル時間 569 ms
コンパイル使用メモリ 64,228 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 21:18:10
合計ジャッジ時間 1,237 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// 想定解法: DP 全パターン生成 モンテカルロ

#include <iostream>
#include <cstring>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
void rc(int v,int mn,int mx){if(v<mn||mx<v){cerr<<"error"<<endl;}}

const int MAX = 10;
const int MAXV = MAX*6;
ll dp1[MAXV+1];
ll dp2[MAXV+1];

int main(){
    int N, K;
    cin >> N >> K;
    rc(N,1,MAX);
    rc(K,0,N);

    REP(i,MAXV+1) dp1[i] = 0;
    dp1[0] = 1;
    REP(i,N-K) RREP(j,MAXV+1){
        REP(k,6) dp1[j+k+1] += dp1[j]; dp1[j] = 0;
    }

    memcpy(dp2, dp1, sizeof(dp2));

    REP(i,K) RREP(j,MAXV+1){
        REP(k,6) dp1[j+k+1] += dp1[j]; dp1[j] = 0;
        REP(k,3) dp2[j+k+4] += dp2[j]*2; dp2[j] = 0;
    }

    REP(j,MAXV) dp1[j+1] += dp1[j];
    ll sum = dp1[MAXV];
    ll win = 0, total = 0;

    REP(i,MAXV+1){
        if(!dp2[i]) continue;
        win += dp1[i-1] * dp2[i];
        total += sum * dp2[i];
    }
    cout << fixed << setprecision(15) << 1.0*win/total << endl;
    return 0;
}

0