結果
| 問題 |
No.58 イカサマなサイコロ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-04-09 00:23:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 2,573 bytes |
| コンパイル時間 | 1,712 ms |
| コンパイル使用メモリ | 171,988 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-19 05:57:26 |
| 合計ジャッジ時間 | 2,366 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
#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);
}