結果

問題 No.75 回数の期待値の問題
ユーザー simansiman
提出日時 2021-01-03 20:59:37
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,368 bytes
コンパイル時間 6,391 ms
コンパイル使用メモリ 104,460 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-03 18:01:04
合計ジャッジ時間 112,880 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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 = 4.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;
    int 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