Problem:
E: Entangled with Lottery
ICPC で良い成績を収めるには修行が欠かせない．うさぎは ICPC で勝ちたいので，今日も修行をすることにした．
今日の修行は，あみだくじを利用して，未来を読む力をつけて運気を高めようというものである．もちろん直感に頼るだけでなく，綿密な確率計算も欠かせない．
今回考えるあみだくじは，長さ
H
+ 1 センチメートルの縦棒
N
本からなる．うさぎは棒の上部を見て，
N
本のうち 1 本を選ぶことになる．棒の下部には，左から
P
本目の棒の場所にのみ「当たり」と書かれている．あみだくじにはいくつかの横棒が含まれる．横棒の配置に関して，以下の条件を考えよう．
各横棒は，
a
を 1 以上
H
以下の整数として，縦棒の上端から
a
センチメートルの高さにある．
各横棒は，隣り合った 2 本の縦棒のみを結ぶ．
同じ高さには複数の横棒は存在しない．
うさぎはこれらの条件を満たすように
M
本の横棒を引いた．あいにくうさぎは記憶力が良いので，当たりの位置や横棒の位置をすべて覚えてしまっており，あみだくじを楽しめない．そこで友達のねこにさらに横棒を追加してもらうことにした．
まず，うさぎは当たりを狙って
N
本の棒のうち 1 本を選ぶ．その後，ねこは以下の操作をちょうど
K
回行う．
横棒を追加しても上で指定された条件を満たすような場所のうち 1 箇所を無作為に選ぶ．ここで，どの場所も等確率で選ばれるものとする．選んだ場所に横棒を追加する．
そして，うさぎが選んだ棒が当たりであったかを判定する．棒の辿り方は通常のあみだくじと同様である (横棒に出会うたびに隣の縦棒に移る)．うさぎは，可能な限り当たりとなる確率を高くしたい．
Input
H
N
P
M
K
A
1
B
1
...
A
M
B
M
A
i
,
B
i
(1 ≤
i
≤
M
) はうさぎが引いた横棒のうち
i
番目のものが，縦棒の上端から
A
i
センチメートルの高さにあり，左から
B
i
本目の縦棒と左から
B
i
+ 1 本目の縦棒を結ぶことを表す整数である．
2 ≤
H
≤ 500，2 ≤
N
≤ 100，1 ≤
P
≤
N
，1 ≤
M
≤ 100，1 ≤
K
≤ 100，
M
+
K
≤
H
，1 ≤
A
1
<
A
2
< ... <
A
M
≤
H
，1 ≤
B
i
≤
N
- 1 を満たす．
Output
当たりとなる確率が最大となるようにうさぎが棒を選んだときの，当たりとなる確率を 1 行に出力せよ．10
-6
以下の絶対誤差が許容される．
Sample Input 1
9 4 3 2 1
2 1
7 3
Sample Output 1
0.571428571
Sample Input 2
9 4 3 2 3
2 1
7 3
Sample Output 2
0.375661376

Submitted solutions:

code_snippet: // AOJ #2294
// Entangled with Lottery 2025.2.4

#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-14;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    int H, N, P, M, K;
    cin >> H >> N >> P >> M >> K;

    vector<int> used(H+1, -1);
    for(int i=0; i<M; i++){
        int A, B;
        cin >> A >> B;
        used[A] = B;
    }

    vector<int> freeCount(H+2, 0);
    for(int r = H; r >= 1; r--){
        freeCount[r] = freeCount[r+1] + (used[r] == -1 ? 1 : 0);
    }

    vector<vector<double>> dpBelow(N+1, vector<double>(K+1, 0.0)),
                          dpCurrent(N+1, vector<double>(K+1, 0.0));

    for(int i=1; i<=N; i++){
        for(int k2=0; k2<=K; k2++){
            dpBelow[i][k2] = ( (i == P) ? 1.0 : 0.0 );
        }
    }

    for(int r=H; r>=1; r--){
        // 1. 既存横棒ありの場合
        if(used[r] != -1){
            int b = used[r]; 
            for(int i=1; i<=N; i++){
                for(int k2=0; k2<=K; k2++){
                    int nxt = i;
                    if(i == b)   nxt = b+1;
                    else if(i == b+1) nxt = b;
                    dpCurrent[i][k2] = dpBelow[nxt][k2];
                }
            }
        }
        else {
            for(int i=1; i<=N; i++){
                for(int k2=0; k2<=K; k2++){
                    dpCurrent[i][k2] = 0.0;
                }
            }
            if(freeCount[r] == 0){
                for(int i=1; i<=N; i++){
                    dpCurrent[i][0] = dpBelow[i][0];
                }
            }
            else {
                for(int i=1; i<=N; i++){
                    for(int k2=0; k2<=K; k2++){
                        double p_not = 1.0;
                        double val_not = dpBelow[i][k2];

                        double val_choose = 0.0;
                        if(k2 > 0 && freeCount[r] >= k2){
                            double p_choose = (double)k2 / (double)freeCount[r];
                            p_not = 1.0 - p_choose;

                            double sumSwap = 0.0;
                            auto &A = dpBelow;

                            if(i == 1){
                                double a1 = A[1][k2-1];
                                double a2 = A[2][k2-1];
                                sumSwap = a2 + (N-2) * a1;
                            }
                            else if(i == N){
                                double aN   = A[N][k2-1];
                                double aN_1 = A[N-1][k2-1];
                                sumSwap = aN_1 + (N-2) * aN;
                            }
                            else {
                                double ai    = A[i][k2-1];
                                double ai_1  = A[i-1][k2-1];
                                double ai_p1 = A[i+1][k2-1];
                                sumSwap = ai_1 + ai_p1 + (N-3)*ai;
                            }
                            val_choose = p_choose * (1.0/(N-1)) * sumSwap;
                        }
                        dpCurrent[i][k2] = p_not * val_not + val_choose;
                    }
                }
            }
        }
        dpBelow.swap(dpCurrent);
    }
    double ans = 0.0;
    for(int i=1; i<=N; i++){
        ans = max(ans, dpBelow[i][K]);
    }
    cout << fixed << setprecision(9) << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3680
final_rank: 4

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rrep(i, a, b) for (ll i = (ll)(b)-1; i >= (ll)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

int main() {
    int H, N, P, M, K;
    cin >> H >> N >> P >> M >> K;
    P--;
    vector<int> X(H,-1);
    rep(i,0,M) {
        int A, B;
        cin >> A >> B;
        A--, B--;
        X[A] = B;
    }
    auto next = [&](int i, int j) -> int {
        if (i == j) return i+1;
        if (i == j+1) return i-1;
        return i;
    };
    vector DP(2, vector(N, vector<double>(H-M+1,0.0)));
    DP[H&1][P][0] = 1.0;
    rrep(i,0,H) {
        rep(j,0,N) {
            rep(k,0,H-M+1) {
                DP[i&1][j][k] = 0.0;
            }
        }
        if (X[i] != -1) {
            rep(j,0,N) {
                rep(k,0,H-M+1) {
                    DP[i&1][next(j,X[i])][k] += DP[(i+1)&1][j][k];
                }
            }
        }
        else {
            rep(j,0,N) {
                rep(k,0,H-M+1) {
                    if (DP[(i+1)&1][j][k] == 0.0) continue;
                    DP[i&1][j][k] += DP[(i+1)&1][j][k];
                    double Kiyo = (DP[(i+1)&1][j][k] * (double)(k+1) / (double)(H-M-k)) / (double(N-1));
                    if (j == 0) {
                        DP[i&1][j][k+1] += Kiyo * (double)(N-2);
                        DP[i&1][j+1][k+1] += Kiyo;
                    }
                    else if (j == N-1) {
                        DP[i&1][j][k+1] += Kiyo * (double)(N-2);
                        DP[i&1][j-1][k+1] += Kiyo;
                    }
                    else {
                        DP[i&1][j][k+1] += Kiyo * (double)(N-3);
                        DP[i&1][j-1][k+1] += Kiyo;
                        DP[i&1][j+1][k+1] += Kiyo;
                    }
                }
            }
        }
    }
    double ANS = 0, SUM = 0.0;
    rep(i,0,N) {
        chmax(ANS, DP[0][i][K]);
        SUM += DP[0][i][K];
    }
    printf("%.12f\n", ANS / SUM);
}
accuracy: 1
time_ms: 40
memory_kb: 4476
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;

double solve(int H, int N, int P, int M, int K, const vector<int>& A, const vector<int>& B) {
	vector<int> place(H, -1);
	for (int i = 0; i < M; i++) {
		place[A[i]] = B[i];
	}
	const double inv = 1.0 / (N - 1);
	vector<vector<double> > dp(N, vector<double>(K + 1, 0.0)); // dp[position][# of drawn lines]
	dp[P][0] = 1.0;
	for (int i = H - 1; i >= 0; i--) {
		vector<vector<double> > ndp(N, vector<double>(K + 1, 0.0));
		for (int j = 0; j < N; j++) {
			for (int k = 0; k <= K; k++) {
				if (place[i] != -1) {
					int last = (j == place[i] ? place[i] + 1 : j == place[i] + 1 ? place[i] : j);
					ndp[j][k] += dp[last][k];
				}
				else {
					// case that doesn't draw
					ndp[j][k] += dp[j][k];
					// case that draws
					if (k >= 1) {
						double prob = ((N - 1) - (j == 0 || j == N - 1 ? 1 : 2)) * inv;
						ndp[j][k] += dp[j][k - 1] * prob;
						if (j != 0) {
							ndp[j][k] += dp[j - 1][k - 1] * inv;
						}
						if (j != N - 1) {
							ndp[j][k] += dp[j + 1][k - 1] * inv;
						}
					}
				}
			}
		}
		dp = ndp;
	}
	double ans = 0.0, sum = 0.0;
	for (int i = 0; i < N; i++) {
		sum += dp[i][K];
		ans = max(ans, dp[i][K]);
	}
	return ans / sum;
}

int main() {
	int H, N, P, M, K;
	cin >> H >> N >> P >> M >> K;
	P -= 1;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		A[i] -= 1;
		B[i] -= 1;
	}
	double ans = solve(H, N, P, M, K, A, B);
	cout.precision(15);
	cout << fixed << ans << endl;
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3744
final_rank: 6

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int H, N, P, M, K;
    cin >> H >> N >> P >> M >> K;
    vector<int> line(H, -1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        line[--A] = --B;
    }
    vector<vector<double>> dp(N, vector<double>(K + 1, 0)), ndp(N, vector<double>(K + 1, 0));
    dp[--P][0] = 1;
    for (int k = H - 1; k >= 0; k--) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= K; j++) {
                double& val = dp[i][j];
                if (val == 0) continue;
                if (line[k] != -1) {
                    if (i == line[k])
                        ndp[i + 1][j] += val;
                    else if (i == line[k] + 1)
                        ndp[i - 1][j] += val;
                    else
                        ndp[i][j] += val;
                } else {
                    double p = 1.0 * (K - j) / (k + 1 - M);
                    ndp[i][j] += val * (1 - p);
                    if (j < K) {
                        double add = val * p / (N - 1);
                        ndp[i][j + 1] += add * (N - 3);
                        if (i + 1 < N)
                            ndp[i + 1][j + 1] += add;
                        else
                            ndp[i][j + 1] += add;
                        if (i - 1 >= 0)
                            ndp[i - 1][j + 1] += add;
                        else
                            ndp[i][j + 1] += add;
                    }
                }
                val = 0;
            }
        }
        if (line[k] != -1) M--;
        swap(dp, ndp);
    }

    double ans = 0;
    for (int i = 0; i < N; i++) ans = max(ans, dp[i][K]);
    cout << ans << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3676
final_rank: 3

code_snippet: #include <bits/stdc++.h>

#ifdef _MSC_VER
#  include <intrin.h>
#else
#  include <x86intrin.h>
#endif

#include <limits>
#include <type_traits>

namespace suisen {
// ! utility
template <typename ...Types>
using constraints_t = std::enable_if_t<std::conjunction_v<Types...>, std::nullptr_t>;
template <bool cond_v, typename Then, typename OrElse>
constexpr decltype(auto) constexpr_if(Then&& then, OrElse&& or_else) {
    if constexpr (cond_v) {
        return std::forward<Then>(then);
    } else {
        return std::forward<OrElse>(or_else);
    }
}

// ! function
template <typename ReturnType, typename Callable, typename ...Args>
using is_same_as_invoke_result = std::is_same<std::invoke_result_t<Callable, Args...>, ReturnType>;
template <typename F, typename T>
using is_uni_op = is_same_as_invoke_result<T, F, T>;
template <typename F, typename T>
using is_bin_op = is_same_as_invoke_result<T, F, T, T>;

template <typename Comparator, typename T>
using is_comparator = std::is_same<std::invoke_result_t<Comparator, T, T>, bool>;

// ! integral
template <typename T, typename = constraints_t<std::is_integral<T>>>
constexpr int bit_num = std::numeric_limits<std::make_unsigned_t<T>>::digits;
template <typename T, unsigned int n>
struct is_nbit { static constexpr bool value = bit_num<T> == n; };
template <typename T, unsigned int n>
static constexpr bool is_nbit_v = is_nbit<T, n>::value;

// ?
template <typename T>
struct safely_multipliable {};
template <>
struct safely_multipliable<int> { using type = long long; };
template <>
struct safely_multipliable<long long> { using type = __int128_t; };
template <>
struct safely_multipliable<unsigned int> { using type = unsigned long long; };
template <>
struct safely_multipliable<unsigned long int> { using type = __uint128_t; };
template <>
struct safely_multipliable<unsigned long long> { using type = __uint128_t; };
template <>
struct safely_multipliable<float> { using type = float; };
template <>
struct safely_multipliable<double> { using type = double; };
template <>
struct safely_multipliable<long double> { using type = long double; };
template <typename T>
using safely_multipliable_t = typename safely_multipliable<T>::type;

template <typename T, typename = void>
struct rec_value_type {
    using type = T;
};
template <typename T>
struct rec_value_type<T, std::void_t<typename T::value_type>> {
    using type = typename rec_value_type<typename T::value_type>::type;
};
template <typename T>
using rec_value_type_t = typename rec_value_type<T>::type;

} // namespace suisen

// ! type aliases
using i128 = __int128_t;
using u128 = __uint128_t;

template <typename T>
using pq_greater = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <typename T, typename U>
using umap = std::unordered_map<T, U>;

// ! macros (capital: internal macro)
#define OVERLOAD2(_1,_2,name,...) name
#define OVERLOAD3(_1,_2,_3,name,...) name
#define OVERLOAD4(_1,_2,_3,_4,name,...) name

#define REP4(i,l,r,s)  for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l);i<(r);i+=(s))
#define REP3(i,l,r)    REP4(i,l,r,1)
#define REP2(i,n)      REP3(i,0,n)
#define REPINF3(i,l,s) for(std::remove_reference_t<std::remove_const_t<decltype(l)>>i=(l);;i+=(s))
#define REPINF2(i,l)   REPINF3(i,l,1)
#define REPINF1(i)     REPINF2(i,0)
#define RREP4(i,l,r,s) for(std::remove_reference_t<std::remove_const_t<decltype(r)>>i=(l)+fld((r)-(l)-1,s)*(s);i>=(l);i-=(s))
#define RREP3(i,l,r)   RREP4(i,l,r,1)
#define RREP2(i,n)     RREP3(i,0,n)

#define rep(...)    OVERLOAD4(__VA_ARGS__, REP4   , REP3   , REP2   )(__VA_ARGS__)
#define rrep(...)   OVERLOAD4(__VA_ARGS__, RREP4  , RREP3  , RREP2  )(__VA_ARGS__)
#define repinf(...) OVERLOAD3(__VA_ARGS__, REPINF3, REPINF2, REPINF1)(__VA_ARGS__)

#define CAT_I(a, b) a##b
#define CAT(a, b) CAT_I(a, b)
#define UNIQVAR(tag) CAT(tag, __LINE__)
#define loop(n) for (std::remove_reference_t<std::remove_const_t<decltype(n)>> UNIQVAR(loop_variable) = n; UNIQVAR(loop_variable) --> 0;)

#define all(iterable) std::begin(iterable), std::end(iterable)
#define input(type, ...) type __VA_ARGS__; read(__VA_ARGS__)

#ifdef LOCAL
#  define debug(...) debug_internal(#__VA_ARGS__, __VA_ARGS__)

template <class T, class... Args>
void debug_internal(const char* s, T&& first, Args&&... args) {
    constexpr const char* prefix = "[\033[32mDEBUG\033[m] ";
    constexpr const char* open_brakets = sizeof...(args) == 0 ? "" : "(";
    constexpr const char* close_brakets = sizeof...(args) == 0 ? "" : ")";
    std::cerr << prefix << open_brakets << s << close_brakets << ": " << open_brakets << std::forward<T>(first);
    ((std::cerr << ", " << std::forward<Args>(args)), ...);
    std::cerr << close_brakets << "\n";
}

#else
#  define debug(...) void(0)
#endif

// ! I/O utilities

// __int128_t
std::ostream& operator<<(std::ostream& dest, __int128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[128];
        char* d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}
// __uint128_t
std::ostream& operator<<(std::ostream& dest, __uint128_t value) {
    std::ostream::sentry s(dest);
    if (s) {
        char buffer[128];
        char* d = std::end(buffer);
        do {
            --d;
            *d = "0123456789"[value % 10];
            value /= 10;
        } while (value != 0);
        int len = std::end(buffer) - d;
        if (dest.rdbuf()->sputn(d, len) != len) {
            dest.setstate(std::ios_base::badbit);
        }
    }
    return dest;
}

// pair
template <typename T, typename U>
std::ostream& operator<<(std::ostream& out, const std::pair<T, U>& a) {
    return out << a.first << ' ' << a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::ostream& operator<<(std::ostream& out, const std::tuple<Args...>& a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return out;
    } else {
        out << std::get<N>(a);
        if constexpr (N + 1 < std::tuple_size_v<std::tuple<Args...>>) {
            out << ' ';
        }
        return operator<<<N + 1>(out, a);
    }
}
// vector
template <typename T>
std::ostream& operator<<(std::ostream& out, const std::vector<T>& a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
// array
template <typename T, size_t N>
std::ostream& operator<<(std::ostream& out, const std::array<T, N>& a) {
    for (auto it = a.begin(); it != a.end();) {
        out << *it;
        if (++it != a.end()) out << ' ';
    }
    return out;
}
inline void print() { std::cout << '\n'; }
template <typename Head, typename... Tail>
inline void print(const Head& head, const Tail &...tails) {
    std::cout << head;
    if (sizeof...(tails)) std::cout << ' ';
    print(tails...);
}
template <typename Iterable>
auto print_all(const Iterable& v, std::string sep = " ", std::string end = "\n") -> decltype(std::cout << *v.begin(), void()) {
    for (auto it = v.begin(); it != v.end();) {
        std::cout << *it;
        if (++it != v.end()) std::cout << sep;
    }
    std::cout << end;
}

__int128_t parse_i128(std::string& s) {
    __int128_t ret = 0;
    for (int i = 0; i < int(s.size()); i++) if ('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0';
    if (s[0] == '-') ret = -ret;
    return ret;
}
__uint128_t parse_u128(std::string& s) {
    __uint128_t ret = 0;
    for (int i = 0; i < int(s.size()); i++) if ('0' <= s[i] and s[i] <= '9') ret = 10 * ret + s[i] - '0';
    return ret;
}
// __int128_t
std::istream& operator>>(std::istream& in, __int128_t& v) {
    std::string s;
    in >> s;
    v = parse_i128(s);
    return in;
}
// __uint128_t
std::istream& operator>>(std::istream& in, __uint128_t& v) {
    std::string s;
    in >> s;
    v = parse_u128(s);
    return in;
}
// pair
template <typename T, typename U>
std::istream& operator>>(std::istream& in, std::pair<T, U>& a) {
    return in >> a.first >> a.second;
}
// tuple
template <unsigned int N = 0, typename ...Args>
std::istream& operator>>(std::istream& in, std::tuple<Args...>& a) {
    if constexpr (N >= std::tuple_size_v<std::tuple<Args...>>) {
        return in;
    } else {
        return operator>><N + 1>(in >> std::get<N>(a), a);
    }
}
// vector
template <typename T>
std::istream& operator>>(std::istream& in, std::vector<T>& a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
// array
template <typename T, size_t N>
std::istream& operator>>(std::istream& in, std::array<T, N>& a) {
    for (auto it = a.begin(); it != a.end(); ++it) in >> *it;
    return in;
}
template <typename ...Args>
void read(Args &...args) {
    (std::cin >> ... >> args);
}

// ! integral utilities

// Returns pow(-1, n)
template <typename T>
constexpr inline int pow_m1(T n) {
    return -(n & 1) | 1;
}
// Returns pow(-1, n)
template <>
constexpr inline int pow_m1<bool>(bool n) {
    return -int(n) | 1;
}

// Returns floor(x / y)
template <typename T>
constexpr inline T fld(const T x, const T y) {
    return (x ^ y) >= 0 ? x / y : (x - (y + pow_m1(y >= 0))) / y;
}
template <typename T>
constexpr inline T cld(const T x, const T y) {
    return (x ^ y) <= 0 ? x / y : (x + (y + pow_m1(y >= 0))) / y;
}

template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u32(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u32(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
__attribute__((target("popcnt"))) constexpr inline int popcount(const T x) { return _mm_popcnt_u64(x); }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_lz(const T x) { return x ? __builtin_clzll(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 16>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 32>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctz(x) : suisen::bit_num<T>; }
template <typename T, suisen::constraints_t<suisen::is_nbit<T, 64>> = nullptr>
constexpr inline int count_tz(const T x) { return x ? __builtin_ctzll(x) : suisen::bit_num<T>; }
template <typename T>
constexpr inline int floor_log2(const T x) { return suisen::bit_num<T> -1 - count_lz(x); }
template <typename T>
constexpr inline int ceil_log2(const T x) { return floor_log2(x) + ((x & -x) != x); }
template <typename T>
constexpr inline int kth_bit(const T x, const unsigned int k) { return (x >> k) & 1; }
template <typename T>
constexpr inline int parity(const T x) { return popcount(x) & 1; }

// ! container

template <typename T, typename Comparator, suisen::constraints_t<suisen::is_comparator<Comparator, T>> = nullptr>
auto priqueue_comp(const Comparator comparator) {
    return std::priority_queue<T, std::vector<T>, Comparator>(comparator);
}

template <typename Iterable>
auto isize(const Iterable& iterable) -> decltype(int(iterable.size())) {
    return iterable.size();
}

template <typename T, typename Gen, suisen::constraints_t<suisen::is_same_as_invoke_result<T, Gen, int>> = nullptr>
auto generate_vector(int n, Gen generator) {
    std::vector<T> v(n);
    for (int i = 0; i < n; ++i) v[i] = generator(i);
    return v;
}
template <typename T>
auto generate_range_vector(T l, T r) {
    return generate_vector(r - l, [l](int i) { return l + i; });
}
template <typename T>
auto generate_range_vector(T n) {
    return generate_range_vector(0, n);
}

template <typename T>
void sort_unique_erase(std::vector<T>& a) {
    std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());
}

template <typename InputIterator, typename BiConsumer>
auto foreach_adjacent_values(InputIterator first, InputIterator last, BiConsumer f) -> decltype(f(*first++, *last), void()) {
    if (first != last) for (auto itr = first, itl = itr++; itr != last; itl = itr++) f(*itl, *itr);
}
template <typename Container, typename BiConsumer>
auto foreach_adjacent_values(Container c, BiConsumer f) -> decltype(c.begin(), c.end(), void()) {
    foreach_adjacent_values(c.begin(), c.end(), f);
}

// ! other utilities

// x <- min(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmin(T& x, const T& y) {
    if (y >= x) return false;
    x = y;
    return true;
}
// x <- max(x, y). returns true iff `x` has chenged.
template <typename T>
inline bool chmax(T& x, const T& y) {
    if (y <= x) return false;
    x = y;
    return true;
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::string bin(T val, int bit_num = -1) {
    std::string res;
    if (bit_num >= 0) {
        for (int bit = bit_num; bit-- > 0;) res += '0' + ((val >> bit) & 1);
    } else {
        for (; val; val >>= 1) res += '0' + (val & 1);
        std::reverse(res.begin(), res.end());
    }
    return res;
}

template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::vector<T> digits_low_to_high(T val, T base = 10) {
    std::vector<T> res;
    for (; val; val /= base) res.push_back(val % base);
    if (res.empty()) res.push_back(T{ 0 });
    return res;
}
template <typename T, std::enable_if_t<std::is_integral_v<T>, std::nullptr_t> = nullptr>
std::vector<T> digits_high_to_low(T val, T base = 10) {
    auto res = digits_low_to_high(val, base);
    std::reverse(res.begin(), res.end());
    return res;
}

template <typename T>
std::string join(const std::vector<T>& v, const std::string& sep, const std::string& end) {
    std::ostringstream ss;
    for (auto it = v.begin(); it != v.end();) {
        ss << *it;
        if (++it != v.end()) ss << sep;
    }
    ss << end;
    return ss.str();
}

namespace suisen {}
using namespace suisen;
using namespace std;

struct io_setup {
    io_setup(int precision = 20) {
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
        std::cout << std::fixed << std::setprecision(precision);
    }
} io_setup_ {};

// ! code from here

int main() {
    input(int, h, n, p, m, k);
    --p;

    vector<int> bar(h, -1);
    rep(i, m) {
        input(int, a, b);
        --a, --b;
        bar[a] = b;
    }

    vector dp(h + 1, vector(n, vector<double>(k + 2, 0)));
    dp[h][p][0] = 1;
    rrep(i, h) rep(pos, n) rep(use, k + 1) {
        if (bar[i] < 0) {
            dp[i][pos][use] += dp[i + 1][pos][use];
            int lc = pos > 0, rc = pos < n - 1, mc = (n - 1) - lc - rc;
            if (lc) {
                dp[i][pos - 1][use + 1] += dp[i + 1][pos][use] * (use + 1) / (n - 1) / (h - m - use);
            }
            if (rc) {
                dp[i][pos + 1][use + 1] += dp[i + 1][pos][use] * (use + 1)  / (n - 1) / (h - m - use);
            }
            if (mc) {
                dp[i][pos][use + 1] += mc * dp[i + 1][pos][use] * (use + 1)  / (n - 1) / (h - m - use);
            }
        } else {
            int npos;
            if (bar[i] == pos) {
                npos = pos + 1;
            } else if (bar[i] == pos - 1) {
                npos = pos - 1;
            } else {
                npos = pos;
            }
            dp[i][npos][use] += dp[i + 1][pos][use];
        }
    }

    vector<double> ans(n);
    rep(i, n) {
        ans[i] = dp[0][i][k];
    }
    debug(ans);

    double sum = accumulate(all(ans), 0);
    double val = *max_element(all(ans));
    debug(sum, val);
    print(val);
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 45452
final_rank: 13

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int ami[502];
double dp[2][102][502];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,n,p,m,K; cin >> h >> n >> p >> m >> K;
    p--;
    for(int i=0;i<m;i++){
        int a,b; cin >> a >> b;
        ami[a] = b;
    }
    int cr = 0;
    dp[cr][0][p] = 1.0;
    // 高さを選ぶ確率は最後にまとめて
    for(int i=h;i>0;i--){
        int nx = (1^cr);
        for(int j=0;j<=K;j++){
            for(int k=0;k<n;k++){
                dp[nx][j][k] = 0;
            }
        }
        for(int j=0;j<=K;j++){
            for(int k=0;k<n;k++){
                if(ami[i]){
                    if(ami[i] == k){
                        dp[nx][j][k-1] += dp[cr][j][k];
                    }
                    else if(ami[i] == k+1){
                        dp[nx][j][k+1] += dp[cr][j][k];
                    }
                    else{
                        dp[nx][j][k] += dp[cr][j][k];
                    }
                }
                else{
                    dp[nx][j][k] += dp[cr][j][k];
                    if(j == K)continue;
                    if(k == 0){
                        dp[nx][j+1][1] += dp[cr][j][k]/(double)(n-1);
                        dp[nx][j+1][0] += dp[cr][j][k]*(n-2)/(double)(n-1);
                    }
                    else if(k+1 == n){
                        dp[nx][j+1][n-2] += dp[cr][j][k]/(double)(n-1);
                        dp[nx][j+1][n-1] += dp[cr][j][k]*(n-2)/(double)(n-1);
                    }
                    else{
                        dp[nx][j+1][k] += dp[cr][j][k]*(n-3)/(double)(n-1);
                        dp[nx][j+1][k+1] += dp[cr][j][k]/(double)(n-1);
                        dp[nx][j+1][k-1] += dp[cr][j][k]/(double)(n-1);
                    }
                }
            }
        }
        cr = nx;
    }
    double res = 0;
    for(int i=0;i<n;i++){
        res = max(res, dp[cr][K][i]);
    }
    for(int j=1;j<=K;j++){
        res *= (K+1-j)/(double)(h-m-j+1);
    }
    printf("%.9f\n",res);
}
accuracy: 1
time_ms: 10
memory_kb: 4360
final_rank: 7

code_snippet: #pragma GCC ta g("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define DEBUG
#ifdef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = (1<<30)-1;
const ll linf = 1LL<<61;
const int MAX = 510000;
int dy[8] = {0,1,0,-1,1,-1,-1,1};
int dx[8] = {-1,0,1,0,1,-1,1,-1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    int sz = a.size();
    for(auto itr = a.begin(); itr != a.end(); itr++){
		cout << *itr;
        sz--;
        if(sz) cout << " ";
	}
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){
	cout << a << " " << b << "\n";
}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
void mark() {cout << "#" << "\n";}
ll pcount(ll x) {return __builtin_popcountll(x);}
//#include <atcoder/maxflow>
//using namespace atcoder;
//const int mod = 1e9 + 7;
const int mod = 998244353;

double dp[2][101][101];

int main(){
    int h,n,p,m,k; cin >> h >> n >> p >> m >> k; p--;
    vector<int> x(h,-1);
    rep(i,m){
        int a,b; cin >> a >> b; a--; b--;
        x[a] = b;
    }
    reverse(all(x));
    dp[0][0][p] = 1;
    int K = h-m;
    rep(i,h){
        rep(j,k+1) rep(l,n) dp[1][j][l] = 0;
        if(x[i] == -1){
            rep(j,k+1) rep(l,n){
                dp[1][j][l] += dp[0][j][l] * (K-(k-j)) / K;
                dp[1][j+1][l] += dp[0][j][l] * (k-j) / K * (n-3+(l==0||l==n-1)) / (n-1); 
                if(l>0) dp[1][j+1][l-1] += dp[0][j][l] * (k-j) / K / (n-1);
                if(l<n-1) dp[1][j+1][l+1] += dp[0][j][l] * (k-j) / K / (n-1);
            }
            K--;
        }else{
            rep(j,k+1) rep(l,n){
                if(x[i] == l) dp[1][j][l+1] += dp[0][j][l];
                else if(x[i] == l-1) dp[1][j][l-1] += dp[0][j][l];
                else dp[1][j][l] += dp[0][j][l];
            }
        }
        swap(dp[0],dp[1]);
    }
    double ans = 0;
    rep(i,n) chmax(ans, dp[0][k][i]);
    printf("%.10f\n",ans);
}
accuracy: 1
time_ms: 10
memory_kb: 3712
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(10);
  int H, N, P, M, K;
  cin >> H >> N >> P >> M >> K;
  P--;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }
  vector<int> x(H, -1);
  for (int i = 0; i < M; i++){
    x[A[i]] = B[i];
  }
  vector<vector<double>> dp(K + 1, vector<double>(N, 0));
  dp[0][P] = 1;
  int cnt = H - M;
  for (int i = H - 1; i >= 0; i--){
    if (x[i] != -1){
      for (int j = 0; j <= K; j++){
        swap(dp[j][x[i]], dp[j][x[i] + 1]);
      }
    } else {
      vector<vector<double>> dp2(K + 1, vector<double>(N, 0));
      for (int j = 0; j <= K; j++){
        double p = (double) (K - j) / cnt;
        for (int k = 0; k < N; k++){
          dp2[j][k] += dp[j][k] * (1 - p);
          if (j < K){
            double q = p;
            if (k > 0){
              dp2[j + 1][k - 1] += dp[j][k] * p / (N - 1);
              q -= p / (N - 1);
            }
            if (k < N - 1){
              dp2[j + 1][k + 1] += dp[j][k] * p / (N - 1);
              q -= p / (N - 1);
            }
            dp2[j + 1][k] += dp[j][k] * q;
          }
        }
      }
      swap(dp, dp2);
      cnt--;
    }
  }
  double ans = 0;
  for (int i = 0; i < N; i++){
    ans = max(ans, dp[K][i]);
  }
  cout << ans << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 3380
final_rank: 11

code_snippet: #include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>

using namespace std;
using ldouble = long double;

void solve() {
    int h, n, s, m, k;
    cin >> h >> n >> s >> m >> k;

    vector<int> ls(h, -1);
    while (m--) {
        int x, y;
        cin >> x >> y;
        ls[--x] = --y;
    }

    auto dp = vector(k + 1, vector(n, 0.L));
    dp[0][--s] = 1;
    // 引いた横線の数、当たりの位置

    int x = 0;  // 横線を引ける段の数

    reverse(ls.begin(), ls.end());
    for (auto py : ls) {
        // 下にある段数
        if (py != -1) {
            for (int i = 0; i <= k; ++i) {
                swap(dp[i][py], dp[i][py + 1]);
            }

        } else {
            ++x;
            auto ndp = vector(k + 1, vector(n, 0.L));

            for (int i = 0; i <= k; ++i) {
                // 線を引く確率
                auto prob = ldouble(i) / x;

                // 線を引かない場合
                for (int y = 0; y < n; ++y) {
                    ndp[i][y] += dp[i][y] * (1 - prob);
                }

                if (i > 0) {
                    // 線を引く場合
                    for (int y = 0; y < n; ++y) {
                        int stay = n - 1;

                        if (y + 1 < n) {
                            // (y,y+1)
                            ndp[i][y] += dp[i - 1][y + 1] * prob / (n - 1);
                            --stay;
                        }
                        if (y - 1 >= 0) {
                            // (y-1,y)
                            ndp[i][y] += dp[i - 1][y - 1] * prob / (n - 1);
                            --stay;
                        }

                        ndp[i][y] += dp[i - 1][y] * prob * stay / (n - 1);
                    }
                }
            }

            swap(dp, ndp);
        }
    }

    cout << *max_element(dp[k].begin(), dp[k].end()) << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    solve();

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3720
final_rank: 8

code_snippet: #include<iostream>
#include<iomanip>
using namespace std;
int H,N,P,M,K;
int id[505];
double dp[2][102][505];
main()
{
	cin>>H>>N>>P>>M>>K;
	P--;
	for(int i=0;i<M;i++)
	{
		int a,b;cin>>a>>b;
		id[a-1]=b;
	}
	int now=0;
	dp[now][0][P]=1;
	for(int i=H;i--;)
	{
		int nxt=1-now;
		for(int j=0;j<=K;j++)for(int k=0;k<N;k++)dp[nxt][j][k]=0;
		for(int j=0;j<=K;j++)for(int k=0;k<N;k++)
		{
			if(id[i])
			{
				if(k==id[i]-1)dp[nxt][j][k+1]+=dp[now][j][k];
				else if(k==id[i])dp[nxt][j][k-1]+=dp[now][j][k];
				else dp[nxt][j][k]+=dp[now][j][k];
			}
			else
			{
				dp[nxt][j][k]+=dp[now][j][k];
				if(k==0)
				{
					dp[nxt][j+1][k]+=dp[now][j][k]*(N-2)/(N-1);
					dp[nxt][j+1][k+1]+=dp[now][j][k]/(N-1);
				}
				else if(k+1==N)
				{
					dp[nxt][j+1][k]+=dp[now][j][k]*(N-2)/(N-1);
					dp[nxt][j+1][k-1]+=dp[now][j][k]/(N-1);
				}
				else
				{
					dp[nxt][j+1][k]+=dp[now][j][k]*(N-3)/(N-1);
					dp[nxt][j+1][k-1]+=dp[now][j][k]/(N-1);
					dp[nxt][j+1][k+1]+=dp[now][j][k]/(N-1);
				}
			}
		}
		now=nxt;
	}
	double ans=0;
	for(int i=0;i<N;i++)if(ans<dp[now][K][i])ans=dp[now][K][i];
	for(int i=1;i<=K;i++)ans=ans*i/(H-M-i+1);
	cout<<fixed<<setprecision(16)<<ans<<endl;
}
accuracy: 1
time_ms: 40
memory_kb: 4084
final_rank: 9

code_snippet: #include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"
#include "complex"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;




int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> H >> N >> T >> M >> K;
	T--;
	vector<vector<vector<long double>>>dp(H + 1, vector<vector<long double>>(K+1,vector<long double>(N)));
	dp[H][K][T] = 1;
	vector<int>v(H, -1);
	vector<int>sum(H, 1);
	while (M--) {
		cin >> L >> R;
		L--, R--;
		v[L] = R;
		sum[L]--;
	}
	for (int i = 1; i < H; i++) {
		sum[i] += sum[i - 1];
	}
	if (N <= 2) {
		cout << 1 << endl;
		return 0;
	}

	for (int i = H - 1; i >= 0; i--) {
		if (v[i] == -1) {
			for (int j = 0; j <= min(K, sum[i] + 0LL); j++) {
				long double p = j;
				p /= sum[i];
				for (int k = 0; k < N; k++) {
					if (j) {
						if (k == 0) {
							dp[i][j - 1][k + 1] += dp[i + 1][j][k] * p / (N - 1);
							dp[i][j - 1][k] += dp[i + 1][j][k] * p *(N - 2) / (N - 1);
							dp[i][j][k] += dp[i + 1][j][k] * (1 - p);
						}
						else if (k + 1 == N) {
							dp[i][j - 1][k - 1] += dp[i + 1][j][k] * p / (N - 1);
							dp[i][j - 1][k] += dp[i + 1][j][k] * p *(N - 2) / (N - 1);
							dp[i][j][k] += dp[i + 1][j][k] * (1 - p);
						}
						else {
							dp[i][j - 1][k - 1] += dp[i + 1][j][k] * p / (N - 1);
							dp[i][j - 1][k + 1] += dp[i + 1][j][k] * p / (N - 1);
							dp[i][j - 1][k] += dp[i + 1][j][k] * p *(N - 3) / (N - 1);
							dp[i][j][k] += dp[i + 1][j][k] * (1 - p);
						}
					}
					else {
						dp[i][j][k] = dp[i + 1][j][k];
					}
				}
			}
		}
		else {
			for (int j = 0; j <= K; j++) {
				dp[i][j] = dp[i + 1][j];
				swap(dp[i][j][v[i]], dp[i][j][v[i] + 1]);
			}
		}
	}
	cout <<setprecision(20)<< *max_element(dp.front().front().begin(), dp.front().front().end()) << endl;
}
accuracy: 1
time_ms: 60
memory_kb: 84516
final_rank: 18

code_snippet: #include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long long INF = 1e18;
//const ll mod = 1000000007;
ll H, N, P, M, K;
map<ll, ll> mp;
long double Prev[505][505];
long double Next[505][505];
long double combination[505][505];
ll emp = 0;
int main() {
    for(int i = 0; i <= 500; i++) {
        combination[i][0] = 1;
        for(int j = 1; j <= i; j++) {
            combination[i][j] = combination[i-1][j] + combination[i-1][j-1];
            //cerr << combination[i][j] << endl;
        }
    }
    cin >> H >> N >> P >> M >> K;
    P--;
    for(int i = 0; i < M; i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        mp[a] = b;
    }
    Prev[0][P] = 1;
    for(int h = H - 1; h >= 0; h--) {
        //cerr << "---" << h << "---" << endl;
        for(int i = 0; i <= 500; i++) {
            for(int j = 0; j <= 500; j++) {
                Next[i][j] = 0;
            }
        }
        if(mp.count(h)) {
            for(int i = 0; i <= K; i++) {
                for(int j = 0; j < N; j++) {
                    Next[i][j] = Prev[i][j];
                }
                ll idx = mp[h];
                swap(Next[i][idx], Next[i][idx+1]);
            }
        } else {
            emp++;
            for(int i = 0; i <= K; i++) {
                for(int j = 0; j < N; j++) {
                    Next[i][j] += Prev[i][j];
                }
            }
            for(int i = 0; i <= K; i++) {
                for(ll j = 0; j < N; j++) {
                    Next[i+1][j] += Prev[i][j] * (N - 3) / (N - 1);
                    Next[i+1][max(j-1, 0LL)] += Prev[i][j] / (N - 1);
                    Next[i+1][min(j+1, N-1)] += Prev[i][j] / (N - 1);
                }
            }
        }
        swap(Prev, Next);
        /*
        for(int k = 0; k <= K; k++) {
            cerr << "-" << k << "-" << endl;
            for(int i = 0; i < N; i++) cerr << Prev[k][i] << " ";
            cerr << endl;
        }
        */
    }
    long double ans = 0;
    for(int i = 0; i < N; i++) {
        chmax(ans, Prev[K][i]);
    }
    ans /= combination[emp][K];
    cout << fixed << setprecision(30) << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 540
memory_kb: 15052
final_rank: 14

code_snippet: #include <bits/stdc++.h>
using namespace std;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(12), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
double dp[2][110][110][110]; // dp[i][j][k][l] = (curr=i, cnt=j, k -> l)
int main() {
    int H, N, P, M, K; cin >> H >> N >> P >> M >> K; P--;
    vector<int> A(H + 1, -1);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; b--;
        A[a] = b; // connect b and b+1
    }
    for (int k = 0; k < N; k++) {
        dp[0][0][k][k] = 1.0;
    }
    for (int i = 1; i <= H; i++) {
        for (int j = 0; j <= K; j++) {
            for (int k = 0; k < N; k++) {
                for (int l = 0; l < N; l++) {
                    dp[i%2][j][k][l] = 0;
                }
            }
        }
        if (A[i] >= 0) {
            for (int j = 0; j <= K; j++) {
                for (int k = 0; k < N; k++) {
                    for (int l = 0; l < N; l++) {
                        int from = 0;
                        if (A[i] == l) from = A[i] + 1;
                        else if (A[i] + 1 == l) from = A[i];
                        else from = l;
                        dp[i%2][j][k][l] = dp[(i-1)%2][j][k][from];
                    }
                }
            }
        } else {
            for (int j = 0; j <= K; j++) {
                double line = clamp((K - j) / (H - M - i + 1.0), 0.0, 1.0);
                double noline = 1.0 - line;
                for (int k = 0; k < N; k++) {
                    for (int l = 0; l < N; l++) {
                        double line_P = line / (N - 1);
                        double line_L = l == 0 ? 0.0 : line_P;
                        double line_R = l == N-1 ? 0.0 : line_P;
                        double line_N = line - line_L - line_R;
                        if (j == K) {
                            dp[i%2][j][k][l] += dp[(i-1)%2][j][k][l];
                        } else {
                            dp[i%2][j][k][l] += noline * dp[(i-1)%2][j][k][l];
                            if (l+1<N) dp[i%2][j+1][k][l+1] += line_R * dp[(i-1)%2][j][k][l];
                            if (l-1>=0) dp[i%2][j+1][k][l-1] += line_L * dp[(i-1)%2][j][k][l];
                            dp[i%2][j+1][k][l] += line_N * dp[(i-1)%2][j][k][l];
                        }
                    }
                }
            }
        }
        if (A[i] != -1) M--;
    }
    double ans = 0.0;
    for (int k = 0; k < N; k++) {
        ans = max(ans, dp[H%2][K][k][P]);
    }
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 1260
memory_kb: 23968
final_rank: 20

code_snippet: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <list>
#include <string>
#include <iomanip>
#include <queue>

using namespace std;

constexpr int inf = 1e9 + 7;

int main(){

  int h, n, p, m, k;
  cin >> h >> n >> p >> m >> k;
  --p;

  // amida[i][j] := 左からi番目の棒とi+1番目の棒の間に高さjの位置に横棒があるか
  vector<vector<bool>> amida (n - 1, vector<bool>(h, false));

  for(int i = 0; i < m; ++i){
    int a, b;
    cin >> a >> b;
    --a, --b;
    amida[b][a] = true;
  }

  // k本の横棒をランダムに引く

  // 下からやる
  // dp[i][j][k] := 高さiにいるときに横からj番目の棒へ追加の棒をk回使用したときの確率
  vector<vector<vector<double>>> prob(h + 1, vector<vector<double>>(n, vector<double>(k + 1, 0.0)));
  prob[h][p][0] = 1.0;

  vector<bool> used_y(h, false);

  // 置くことができる総数
  int can_set_num = 0;
  for(int y = 0; y < h; ++y){
    bool used = false;
    for(int i = 0; i < n - 1; ++i){
      used = used || amida[i][y];
    }
    used_y[y] = used;
    if(used) continue;
    can_set_num++;
  }
  double not_used = can_set_num;

  for(int y = h; y > 0; --y){
    for(int t = 0; t <= k; ++t){
      for(int i = 0; i < n; ++i){

        // そもそも横軸があった
        if(used_y[y - 1]){
          // 確定で移動
          if (i < n-1 && amida[i][y-1]) {
            prob[y-1][i+1][t] += prob[y][i][t];
          }
          else if (i > 0 && amida[i-1][y-1]) {
            prob[y-1][i-1][t] += prob[y][i][t];
          }
          else {
            prob[y-1][i][t] += prob[y][i][t];
          }
        }
        else{
          double use = (k-t)/not_used;
          double nuse = 1-use;
          double nm1 = 1.0;
          nm1 /= n-1;
          //int can_set = can_set_num - t * (n - 1);
          // 横軸を入れる場合
          if (t < k) {
          if (i == 0) {
            prob[y-1][i+1][t+1] += prob[y][i][t]*use*nm1;
            prob[y-1][i][t+1] += prob[y][i][t]*use*(1.0-nm1);
          }
          else if (i == n-1) {
            prob[y-1][i-1][t+1] += prob[y][i][t]*use*nm1;
            prob[y-1][i][t+1] += prob[y][i][t]*use*(1.0-nm1);
          }
          else {
            prob[y-1][i-1][t+1] += prob[y][i][t]*use*nm1;
            prob[y-1][i+1][t+1] += prob[y][i][t]*use*nm1;
            prob[y-1][i][t+1] += prob[y][i][t]*use*(1.0-2.0*nm1);
          }
          // 入れない場合
          prob[y-1][i][t] += prob[y][i][t]*nuse;
          }
          else {
            // 入れない場合
            prob[y-1][i][t] += prob[y][i][t];
          }
        }
      
      }
    }
    if(!used_y[y - 1]) {
      not_used -= 1.0;
    }
  }

  //double ans = *max_element(prob[0].begin(), prob[0].end());

  double ans = 0.0;
  for(int i = 0; i < n; ++i) ans = max(ans, prob[0][i][k]);

  cout << fixed << setprecision(15) << ans << endl;

  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 44340
final_rank: 12

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005;
//const int INF=1<<30;
const ll INF=1LL<<60;

double dp[505][105][105];//高さi,j回使った、kにいる
int hen[505];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,N,P,M,K;cin>>H>>N>>P>>M>>K;
    
    memset(hen,-1,sizeof(hen));
    for(int i=0;i<M;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        hen[H-a]=b;
    }
    
    P--;
    
    dp[0][0][P]=1;
    
    int rem=H-M;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<=K;j++){
            for(int k=0;k<N;k++){
                //if(dp[i][j][k]==0) continue;
                
                if(hen[i+1]==-1){
                    double p=double(K-j)/rem;
                    
                    dp[i+1][j][k]+=dp[i][j][k]*(1.0-p);
                    
                    for(int l=0;l<N-1;l++){
                        if(k==l){
                            dp[i+1][j+1][k]+=dp[i][j][k+1]*p/(N-1);
                        }else if(k==l+1){
                            dp[i+1][j+1][k]+=dp[i][j][k-1]*p/(N-1);
                        }else{
                            dp[i+1][j+1][k]+=dp[i][j][k]*p/(N-1);
                        }
                    }
                }else{
                    if(k==hen[i+1]){
                        dp[i+1][j][k]+=dp[i][j][k+1];
                    }else if(k==hen[i+1]+1){
                        dp[i+1][j][k]+=dp[i][j][k-1];
                    }else{
                        dp[i+1][j][k]+=dp[i][j][k];
                    }
                }
            }
        }
        if(hen[i+1]==-1) rem--;
    }
    
    double ans=0;
    
    for(int i=0;i<N;i++){
        chmax(ans,dp[H][K][i]);
    }
    
    cout<<setprecision(25)<<ans<<endl;
}
accuracy: 1
time_ms: 840
memory_kb: 46656
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(i,n) for(auto &i:(n))
#define lambda(RES,...) (function<RES(__VA_ARGS__)>) [&](__VA_ARGS__) -> RES
#define method(NAME,RES,...) function<RES(__VA_ARGS__)>NAME =  [&](__VA_ARGS__) -> RES
#define all(x) (x).begin(),(x).end()
#define bit(x) (1ll<<(x))

template<class t>
using priority_queuer = priority_queue<t,vector<t>,greater<t>>;
template<class t>
using vvector = vector<vector<t>>;
using pii = pair<int,int>;
using ll = long long;
template<class t,class u>
bool chmin(t&a,u b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
template<class t,class u>
bool chmax(t&a,u b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

ll in(){
    ll res;
    cin >> res;
    return res;
}


template<class t>
t in(){
    t res;
    cin >> res;
    return res;
}


const ll INF = 1e9;

double func(){
    int h = in();
    int n = in();
    int p = in()-1;
    int m = in();
    int k = in();
    vector<int> left(h,-1);
    rep(i,m){
        int a = in();
        int b = in();
        left[a-1] = b-1;
    }
    method(toint,int,int y,int x,int rem){
        return rem + (k+1) * (x + n * y);
    };

    vector<double> dp(toint(h+1,n,k),-1);
    method(func,double,int y,int x,int rem,int space){
        if(rem>space)return 0;
        if(y==h){
            return x == p and !rem;
        }
        double &it = dp[toint(y,x,rem)];
        if(it>=0)return it;
        it = 0;
        if(left[y]>=0){
            if(left[y]==x){
                ++x;
            }else if(left[y]+1==x){
                --x;
            }
            it += func(y+1,x,rem,space);
        }else{ 
            if(rem){
                int cnt = 0;
                if(x){
                    it += func(y+1,x-1,rem-1,space-1) * ((double)rem/space) * ((double)1/(n-1));
                    ++cnt;
                }
                if(x+1<n){
                    it += func(y+1,x+1,rem-1,space-1) * ((double)rem/space) * ((double)1/(n-1));
                    ++cnt;
                }
                it += func(y+1,x,rem-1,space-1) * ((double)rem/space) * ((double)(n-cnt-1)/(n-1));
            }
            it += func(y+1,x,rem,space-1) * (1-((double)rem/space)) ;
        }
        return it;
    };
    double res = 0;
    rep(i,n){
        chmax(res,func(0,i,k,h-m));
    }
    return res;
}

int main(){
    printf("%.20lf\n",func());
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 42640
final_rank: 15

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<cassert>

using namespace std;

void solve(){
    vector<vector<bool>> bo;
    vector<int> bo2;
    int H, N, P, M, K;

    double ans = 0;

    cin>>H>>N>>P>>M>>K;

    bo.resize(H+2, vector<bool>(N+2));
    bo2.resize(H+2);

    for(int i = 0; i < M; i++){
        int A, B;

        cin>>A>>B;

        bo[H - A + 1][B] = true;
        bo2[H - A + 1] = B;
    }

    
    int m = 0;
    vector<vector<double>> dp(K+2, vector<double>(N+2));
    dp[0][P] = 1;
    
    for(int j = 1; j <= H; j++){
        vector<vector<double>> nex(K+2, vector<double>(N+2));
        for(int l = min(K, m); l >= 0; l--) {
            if(bo2[j]) {
                for(int k = 1; k <= N; k++){
                    if(bo[j][k]) {
                      nex[l][k+1] += dp[l][k];
                    } else if(bo[j][k-1]) {
                      nex[l][k-1] += dp[l][k];
                    } else {
                      nex[l][k] += dp[l][k];
                    }
                }
            } else {
                double A = (K - l);
                double B = (H - M - m);
                double C = H - M - m - (K - l);

                double pro = A / (B * (N - 1));
                double pro11 = C / B;
                double pro12 = pro * (N - 2);
                double pro22 = pro * (N - 3);
                
                for(int k = 1; k <= N; k++){
                    nex[l+1][k+1] += dp[l][k] * pro;
                    nex[l][k] += dp[l][k] * pro11;
                    nex[l+1][k-1] += dp[l][k] * pro;
                    
                    if(k == 1 || k == N)nex[l+1][k] += dp[l][k] * pro12;
                    else nex[l+1][k] += dp[l][k] * pro22;
                }
                
            }
        }
        swap(dp, nex);
        if(bo2[j] == false) m++;
    }
    
    for(int i = 1; i <= N; i++) ans = max(ans, dp[K][i]);

    cout<<ans<<endl;
}

signed main(){
    cout<<fixed<<setprecision(10);

    solve();

}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<cassert>

using namespace std;

void solve(){
    vector<vector<bool>> bo;
    vector<int> bo2;
    int H, N, P, M, K;

    double ans = 0;

    cin>>H>>N>>P>>M>>K;

    bo.resize(H+2, vector<bool>(N+2));
    bo2.resize(H+2);

    for(int i = 0; i < M; i++){
        int A, B;

        cin>>A>>B;

        bo[H - A + 1][B] = true;
        bo2[H - A + 1] = B;
    }

    
    int m = 0;
    vector<vector<double>> dp(K+2, vector<double>(N+2));
    dp[0][P] = 1;
    
    for(int j = 1; j <= H; j++){
        vector<vector<double>> nex(K+2, vector<double>(N+2));
        for(int l = min(K, m); l >= 0; l--) {
            if(bo2[j]) {
                for(int k = 1; k <= N; k++){
                    if(bo[j][k]) {
                      nex[l][k+1] += dp[l][k];
                    } else if(bo[j][k-1]) {
                      nex[l][k-1] += dp[l][k];
                    } else {
                      nex[l][k] += dp[l][k];
                    }
                }
            } else {
                double A = (K - l);
                double B = (H - M - m);
                double C = H - M - m - (K - l);

                double pro = A / (B * (N - 1));
                double pro11 = C / B;
                double pro12 = pro * (N - 2);
                double pro22 = pro * (N - 3);
                
                for(int k = 1; k <= N; k++){
                    nex[l+1][k+1] += dp[l][k] * pro;
                    nex[l][k] += dp[l][k] * pro11;
                    nex[l+1][k-1] += dp[l][k] * pro;
                    
                    if(k == 1 || k == N)nex[l+1][k] += dp[l][k] * pro12;
                    else nex[l+1][k] += dp[l][k] * pro22;
                }
                
            }
        }
        dp = nex;
        if(bo2[j] == false) m++;
    }
    
    for(int i = 1; i <= N; i++) ans = max(ans, dp[K][i]);

    cout<<ans<<endl;
}

signed main(){
    cout<<fixed<<setprecision(10);

    solve();

}
accuracy: 1
time_ms: 10
memory_kb: 3444
final_rank: 2

code_snippet: #include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<iomanip>
#include<cassert>

using namespace std;

void solve(){
    vector<vector<bool>> bo;
    vector<int> bo2;
    int H, N, P, M, K;

    double ans = 0;

    cin>>H>>N>>P>>M>>K;

    bo.resize(H+2, vector<bool>(N+2));
    bo2.resize(H+2);

    for(int i = 0; i < M; i++){
        int A, B;

        cin>>A>>B;

        bo[A][B] = true;
        bo2[A] = B;
    }

    
    for(int i = 1; i <= N; i++){
        int m = 0;
        vector<vector<double>> dp(K+2, vector<double>(N+2));
        dp[0][i] = 1;
        
        for(int j = 1; j <= H; j++){
            vector<vector<double>> nex(K+2, vector<double>(N+2));
            for(int l = min(K, m); l >= 0; l--) {
                if(bo2[j]) {
                    for(int k = 1; k <= N; k++){
                        if(bo[j][k]) {
                          nex[l][k+1] += dp[l][k];
                        } else if(bo[j][k-1]) {
                          nex[l][k-1] += dp[l][k];
                        } else {
                          nex[l][k] += dp[l][k];
                        }
                    }
                } else {
                    double A = (K - l);
                    double B = (H - M - m);
                    double C = H - M - m - (K - l);

                    double pro = A / (B * (N - 1));
                    double pro11 = C / B;
                    double pro12 = pro * (N - 2);
                    double pro22 = pro * (N - 3);
                    
                    for(int k = 1; k <= N; k++){
                        nex[l+1][k+1] += dp[l][k] * pro;
                        nex[l][k] += dp[l][k] * pro11;
                        nex[l+1][k-1] += dp[l][k] * pro;
                        
                        if(k == 1 || k == N)nex[l+1][k] += dp[l][k] * pro12;
                        else nex[l+1][k] += dp[l][k] * pro22;
                    }
                    
                }
            }
            dp = nex;
            if(bo2[j] == false) m++;
        }
        ans = max(ans, dp[K][P]);
    }

    cout<<ans<<endl;
}

signed main(){
    cout<<fixed<<setprecision(10);

    solve();

}
accuracy: 1
time_ms: 1180
memory_kb: 3448
final_rank: 17

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define foreach(i,n) for(auto &i:(n))
#define lambda(RES,...) (function<RES(__VA_ARGS__)>) [&](__VA_ARGS__) -> RES
#define method(NAME,RES,...) function<RES(__VA_ARGS__)>NAME =  [&](__VA_ARGS__) -> RES
#define all(x) (x).begin(),(x).end()
#define bit(x) (1ll<<(x))

template<class t>
using priority_queuer = priority_queue<t,vector<t>,greater<t>>;
template<class t>
using vvector = vector<vector<t>>;
using pii = pair<int,int>;
using ll = long long;
template<class t,class u>
bool chmin(t&a,u b){
    if(a>b){
        a = b;
        return true;
    }
    return false;
}
template<class t,class u>
bool chmax(t&a,u b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

ll in(){
    ll res;
    cin >> res;
    return res;
}


template<class t>
t in(){
    t res;
    cin >> res;
    return res;
}


const ll INF = 1e9;

double func(){
    int h = in();
    int n = in();
    int p = in()-1;
    int m = in();
    int k = in();
    vector<int> left(h,-1);
    rep(i,m){
        int a = in();
        int b = in();
        left[a-1] = b-1;
    }
    method(toint,int,int y,int x,int rem){
        return rem + (k+1) * (x + n * y);
    };

    vector<double> dp(toint(h+1,n,k),-1);
    method(func,double,int y,int x,int rem,int space){
        if(rem>space)return 0;
        if(y==h){
            return x == p and !rem;
        }
        double &it = dp[toint(y,x,rem)];
        if(it>=0)return it;
        it = 0;
        if(left[y]>=0){
            if(left[y]==x){
                ++x;
            }else if(left[y]+1==x){
                --x;
            }
            it += func(y+1,x,rem,space);
        }else{ 
            if(rem){
                int cnt = 0;
                if(x){
                    it += func(y+1,x-1,rem-1,space-1) * ((double)rem/space) * ((double)1/(n-1));
                    ++cnt;
                }
                if(x+1<n){
                    it += func(y+1,x+1,rem-1,space-1) * ((double)rem/space) * ((double)1/(n-1));
                    ++cnt;
                }
                it += func(y+1,x,rem-1,space-1) * ((double)rem/space) * ((double)(n-cnt-1)/(n-1));
            }
            it += func(y+1,x,rem,space-1) * (1-((double)rem/space)) ;
        }
        return it;
    };
    double res = 0;
    rep(i,n){
        chmax(res,func(0,i,k,h-m));
    }
    return res;
}

int main(){
    printf("%.20lf\n",func());
    return 0;
}
accuracy: 1
time_ms: 130
memory_kb: 42640
final_rank: 15