結果

問題 No.242 ビンゴゲーム
ユーザー kk
提出日時 2021-03-02 20:55:17
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 715 ms / 2,000 ms
コード長 1,330 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 197,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 04:57:17
合計ジャッジ時間 11,794 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 707 ms
6,812 KB
testcase_01 AC 709 ms
6,944 KB
testcase_02 AC 707 ms
6,944 KB
testcase_03 AC 709 ms
6,944 KB
testcase_04 AC 708 ms
6,944 KB
testcase_05 AC 708 ms
6,944 KB
testcase_06 AC 709 ms
6,940 KB
testcase_07 AC 708 ms
6,944 KB
testcase_08 AC 708 ms
6,944 KB
testcase_09 AC 709 ms
6,940 KB
testcase_10 AC 715 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int cnt[26][13];
double prb[100][26];

double success(int n, int k) {
  return n > k ? (double) k / n : 1.0;
}

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

  for (int mask = 0; mask < 1<<25; mask++) {
    int bingo = 0;
    
    // 横
    for (int i = 0; i < 25; i += 5) {
      if ((mask & 0b11111) == 0b11111)
        ++bingo;
    }

    // 縦
    int col = 0b11111;
    for (int i = 0; i < 25; i += 5) {
      col &= mask >> i;
    }
    bingo += __builtin_popcountll(col);

    // 斜
    int x = 1;
    int y = 1;
    for (int i = 0; i < 5; i++) {
      x &= mask >> (5 * i + i);
      y &= mask >> (5 * i + 4 - i);
    }
    bingo += x;
    bingo += y;

    cnt[__builtin_popcountll(mask)][bingo]++;
  }

  
  prb[0][0] = 1.0;
  for (int i = 1; i <= 99; i++) {
    for (int j = 0; j <= 25; j++) {
      prb[i][j] += (1 - success(100-i, 25-j)) * prb[i-1][j];
      if (j > 0)
        prb[i][j] += success(100-i, 26-j) * prb[i-1][j-1];
    }
  }

  int n;
  cin >> n;

  double ret = 0;
  for (int i = 0; i <= 25; i++) {
    int sum = 0;
    int tot = 0;
    for (int j = 0; j <= 12; j++) {
      sum += j * cnt[i][j];
      tot += cnt[i][j];
    }
    ret += prb[n][i] * sum / tot;
  }
   
  cout << fixed << setprecision(12) << ret << endl;
  
  return 0;
}
0