結果

問題 No.75 回数の期待値の問題
ユーザー ninoinuininoinui
提出日時 2020-09-26 05:41:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,838 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 2,167 ms
コンパイル使用メモリ 199,840 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-11 00:32:01
合計ジャッジ時間 10,867 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
4,380 KB
testcase_01 AC 72 ms
4,376 KB
testcase_02 AC 72 ms
4,376 KB
testcase_03 AC 108 ms
4,376 KB
testcase_04 AC 73 ms
4,380 KB
testcase_05 AC 72 ms
4,380 KB
testcase_06 AC 72 ms
4,376 KB
testcase_07 AC 112 ms
4,380 KB
testcase_08 AC 117 ms
4,376 KB
testcase_09 AC 122 ms
4,380 KB
testcase_10 AC 129 ms
4,376 KB
testcase_11 AC 139 ms
4,380 KB
testcase_12 AC 154 ms
4,376 KB
testcase_13 AC 161 ms
4,380 KB
testcase_14 AC 169 ms
4,380 KB
testcase_15 AC 214 ms
4,380 KB
testcase_16 AC 802 ms
4,376 KB
testcase_17 AC 1,427 ms
4,376 KB
testcase_18 AC 1,714 ms
4,380 KB
testcase_19 AC 1,838 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template <typename T, typename U> void cmin(T &a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U> void cmax(T &a, U b) {
  if (a < b) a = b;
}

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  random_device rd;
  mt19937 mt(rd());

  long K;
  cin >> K;
  long ans = 0;
  for (long i = 1e6; i; i--) {
    long sum = 0, cnt = 0;
    while (true) {
      sum += mt() % 6 + 1, cnt++;
      if (sum == K) {
        ans += cnt;
        break;
      } else {
        if (sum > K) sum = 0;
      }
    }
  }
  cout << fixed << setprecision(3) << ans / 1e6 << "\n";
}
0