結果

問題 No.58 イカサマなサイコロ
ユーザー rogi52rogi52
提出日時 2022-09-29 17:43:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,188 bytes
コンパイル時間 2,038 ms
コンパイル使用メモリ 202,964 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-24 05:00:23
合計ジャッジ時間 2,718 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    int N,K; cin >> N >> K;
    using ld = long double;
    int M = 6 * N;
    vector<ld> dp1(M + 1, 0), dp2(M + 1, 0);
    dp1[0] = dp2[0] = 1.0;
    
    for(int i = 1; i <= N; i++) {
        vector<ld> nt(M + 1, 0);
        for(int x : {1, 2, 3, 4, 5, 6})
            for(int s = 0; s <= M; s++) if(s + x <= M)
                    nt[s + x] += dp1[s] / 6.0;
        swap(dp1, nt);
    }

    for(int i = 1; i <= N; i++) {
        vector<ld> nt(M + 1, 0);
        if(i <= K) {
            for(int x : {4, 4, 5, 5, 6, 6})
                for(int s = 0; s <= M; s++) if(s + x <= M)
                    nt[s + x] += dp2[s] / 6.0;
        } else {
            for(int x : {1, 2, 3, 4, 5, 6})
                for(int s = 0; s <= M; s++) if(s + x <= M)
                    nt[s + x] += dp2[s] / 6.0;
        }
        swap(dp2, nt);
    }

    ld ans = 0;
    for(int i = 1; i <= M; i++)
        for(int j = 1; j < i; j++)
            ans += dp1[j] * dp2[i];
    
    cout << fixed << setprecision(20) << ans << endl;
}
0