結果

問題 No.2461 一点張り
ユーザー ldsyb
提出日時 2023-09-08 22:53:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 4,266 ms
コンパイル使用メモリ 256,088 KB
最終ジャッジ日時 2025-02-16 20:18:35
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif

int main()
{
    int64_t T;
    cin >> T;

    for (int64_t t = 0; t < T; t++)
    {
        long double p;
        int64_t k;
        cin >> p >> k;

        map<int64_t, long double> mp;

        auto f = [&](auto &&g, int64_t x) -> long double
        {
            if (mp.find(x) != mp.end())
            {
                return mp[x];
            }

            if (k <= x)
            {
                return mp[x] = 0;
            }

            long double ret = 1 + (1 - p) * g(g, x + 1);

            return mp[x] = ret;
        };

        cout << fixed << setprecision(20) << f(f, 0) << endl;
    }

    return 0;
}
0