結果

問題 No.2123 Chalk Breaker
ユーザー cutmdocutmdo
提出日時 2023-03-07 16:35:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 811 ms
コンパイル使用メモリ 82,568 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-18 05:32:52
合計ジャッジ時間 1,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
4,348 KB
testcase_01 AC 65 ms
4,348 KB
testcase_02 AC 20 ms
4,348 KB
testcase_03 AC 7 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 51 ms
4,348 KB
testcase_06 AC 9 ms
4,348 KB
testcase_07 AC 13 ms
4,348 KB
testcase_08 AC 7 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define PROBLEM "https://yukicoder.me/problems/no/117"

#include <iostream>
#include <iomanip>
#include <vector>

auto Y = [](auto f) {
    return [=](auto&&... args) {
        return f(f, std::forward<decltype(args)>(args)...);
    };
};

using ll = long long;
using std::cout;
using std::cin;
constexpr char endl = '\n';
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;


signed main() {
    ll n;
    cin >> n;

    constexpr double nil = -1.0;
    std::vector<double> dp(n + 1, nil);
    auto f = Y([&](auto&& self, ll n) -> double {
        if(n == 0) { return 0.0; }
        if(dp[n] != nil) { return dp[n]; }

        double sum = 0.0;
        for(int x = 0; x < n; ++x) {
            int y = n - x - 1;
            sum += self(self, x);
            sum += self(self, y);
        }
        auto ans = sum / n + 1;
        dp[n] = ans;
        return ans;
    });

    cout << std::fixed << std::setprecision(12) << f(n) << endl;
}
0