結果

問題 No.75 回数の期待値の問題
ユーザー simansiman
提出日時 2021-01-03 21:03:00
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,938 ms / 5,000 ms
コード長 1,367 bytes
コンパイル時間 4,487 ms
コンパイル使用メモリ 139,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 16:13:44
合計ジャッジ時間 65,020 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,936 ms
5,248 KB
testcase_01 AC 2,937 ms
5,376 KB
testcase_02 AC 2,937 ms
5,376 KB
testcase_03 AC 2,936 ms
5,376 KB
testcase_04 AC 2,937 ms
5,376 KB
testcase_05 AC 2,937 ms
5,376 KB
testcase_06 AC 2,937 ms
5,376 KB
testcase_07 AC 2,936 ms
5,376 KB
testcase_08 AC 2,937 ms
5,376 KB
testcase_09 AC 2,937 ms
5,376 KB
testcase_10 AC 2,938 ms
5,376 KB
testcase_11 AC 2,936 ms
5,376 KB
testcase_12 AC 2,937 ms
5,376 KB
testcase_13 AC 2,937 ms
5,376 KB
testcase_14 AC 2,937 ms
5,376 KB
testcase_15 AC 2,936 ms
5,376 KB
testcase_16 AC 2,937 ms
5,376 KB
testcase_17 AC 2,937 ms
5,376 KB
testcase_18 AC 2,937 ms
5,376 KB
testcase_19 AC 2,936 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

double TIME_LIMIT = 2.5;
ll startCycle;
const ll CYCLE_PER_SEC = 2700000000;

unsigned long long int getCycle() {
  unsigned int low, high;
  __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
  return ((unsigned long long int) low) | ((unsigned long long int) high << 32);
}

double getTime(unsigned long long int begin_cycle) {
  return (double) (getCycle() - begin_cycle) / CYCLE_PER_SEC;
}

unsigned long long xor128() {
  static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
  unsigned long long rt = (rx ^ (rx << 11));
  rx = ry;
  ry = rz;
  rz = rw;
  return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}

int main() {
  int K;
  cin >> K;
  startCycle = getCycle();

  ll loop_cnt = 0;
  ll sum = 0;
  double currentTime = getTime(startCycle);

  while (currentTime < TIME_LIMIT) {
    int n = 0;
    ll cnt = 0;

    while (n < K) {
      n += (xor128() % 6) + 1;
      if (n > K) n = 0;
      ++cnt;
    }

    ++loop_cnt;
    sum += cnt;
    currentTime = getTime(startCycle);
  }

  cout << fixed << setprecision(10) << sum / (double) loop_cnt << endl;

  return 0;
}
0