結果

問題 No.813 ユキちゃんの冒険
ユーザー finefine
提出日時 2019-05-24 23:40:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,951 ms / 2,000 ms
コード長 1,156 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 169,548 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 07:24:07
合計ジャッジ時間 55,448 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,950 ms
4,348 KB
testcase_01 AC 1,950 ms
4,348 KB
testcase_02 AC 1,950 ms
4,348 KB
testcase_03 AC 1,950 ms
4,348 KB
testcase_04 AC 1,949 ms
4,348 KB
testcase_05 AC 1,950 ms
4,348 KB
testcase_06 AC 1,950 ms
4,348 KB
testcase_07 AC 1,950 ms
4,348 KB
testcase_08 AC 1,950 ms
4,348 KB
testcase_09 AC 1,949 ms
4,348 KB
testcase_10 AC 1,951 ms
4,348 KB
testcase_11 AC 1,950 ms
4,348 KB
testcase_12 AC 1,950 ms
4,348 KB
testcase_13 AC 1,950 ms
4,348 KB
testcase_14 AC 1,949 ms
4,348 KB
testcase_15 AC 1,950 ms
4,348 KB
testcase_16 AC 1,950 ms
4,348 KB
testcase_17 AC 1,950 ms
4,348 KB
testcase_18 AC 1,950 ms
4,348 KB
testcase_19 AC 1,950 ms
4,348 KB
testcase_20 AC 1,950 ms
4,348 KB
testcase_21 AC 1,950 ms
4,348 KB
testcase_22 AC 1,951 ms
4,348 KB
testcase_23 AC 1,950 ms
4,348 KB
testcase_24 AC 1,949 ms
4,348 KB
testcase_25 AC 1,951 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr double ticks_per_sec = 2800000000;
constexpr double ticks_per_sec_inv = 1.0 / ticks_per_sec;
inline double rdtsc() { // in seconds
    uint32_t lo, hi;
    asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
    return (((uint64_t)hi << 32) | lo) * ticks_per_sec_inv;
}
constexpr double TLE = 2; // sec

int main() {
    double clock_begin = rdtsc();
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	long double p, q;
	cin >> p >> q;
	q += p;

	int seed = 0;
	mt19937 mt(seed);
	uniform_real_distribution<long double> rnd(0, 1);
	ll cnt = 0;
    double clock_end = clock_begin + TLE * 0.8;
    ll loop_cnt = 0;
    const int MAX_TRY = 200000;
	while (rdtsc() < clock_end) {
        loop_cnt++;
		int cur = 1;
		int d = 1;
		for (int i = 0; i < MAX_TRY; i++) {
			long double val = rnd(mt);
			if (val <= p) {
				d = -d;
				cur += d;
			} else if (val <= q) {
				cur += d;
			} else {
				break;
			}
			if (cur == n + 1) break;
			if (cur == 0) {
				cnt++;
				break;
			}
		}
	}
	cout << fixed << setprecision(15) << (double)cnt / loop_cnt << endl;
	return 0;
}
0