結果

問題 No.58 イカサマなサイコロ
ユーザー phsplsphspls
提出日時 2020-04-09 00:23:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,573 bytes
コンパイル時間 1,821 ms
コンパイル使用メモリ 170,432 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-26 11:17:08
合計ジャッジ時間 2,385 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

llong comb(int n, int k) {
    if(n == 0 || k == 0) return 1;
    if(k > n / 2) k = n - k;
    llong result = 1;
    rep(i, k) result *= n-i;
    rep(i, k) result /= i+1;
    return result;
}

vector<llong> normal_score(int n) {
    vector<llong> scores(6*n+1, 0);
    for(int i1=0; i1<=n; i1++) {
        int res1 = n-i1;
        for(int i2=0; i2<=res1; i2++) {
            int res2 = res1-i2;
            for(int i3=0; i3<=res2; i3++) {
                int res3 = res2-i3;
                for(int i4=0; i4<=res3; i4++) {
                    int res4 = res3-i4;
                    for(int i5=0; i5<=res4; i5++) {
                        int res5 = res4-i5;
                        int i6 = res5;
                        int score = i1 + i2*2 + i3*3 + i4*4 + i5*5 + i6*6;
                        llong c = comb(n, i1) * comb(res1, i2) * comb(res2, i3) * comb(res3, i4) * comb(res4, i5);
                        scores[score] += c;
                    }
                }
            }
        }
    }
    return scores;
}

vector<llong> ikasama_score(int n) {
    vector<llong> scores(6*n+1, 0);
    for(int i1=0; i1<=n; i1++) {
        int res1 = n-i1;
        for(int i2=0; i2<=res1; i2++) {
            int res2 = res1-i2;
            for(int i3=0; i3<=res2; i3++) {
                int res3 = res2-i3;
                for(int i4=0; i4<=res3; i4++) {
                    int res4 = res3-i4;
                    for(int i5=0; i5<=res4; i5++) {
                        int res5 = res4-i5;
                        int i6 = res5;
                        int score = i1*4 + i2*5 + i3*6 + i4*4 + i5*5 + i6*6;
                        llong c = comb(n, i1) * comb(res1, i2) * comb(res2, i3) * comb(res3, i4) * comb(res4, i5);
                        scores[score] += c;
                    }
                }
            }
        }
    }
    return scores;
}

int main() {
    int n, k;
    cin >> n >> k;

    double total = pow(6, n);
    vector<llong> score_jiro = normal_score(n);
    vector<llong> score_taro1 = normal_score(n-k);
    vector<llong> score_taro2 = ikasama_score(k);
    vector<llong> score_taro(6*n+1, 0);
    rep(i, 6*(n-k)+1) {
        rep(j, 6*k+1) {
            score_taro[i+j] += score_taro1[i] * score_taro2[j];
        }
    }
    double result = 0;
    rep(i, 6*n+1) {
        for(int j=i+1; j<6*n+1; j++) {
            result += score_jiro[i] / total * score_taro[j] / total;
        }
    }
    printf("%5f\n", result);
}
0