結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー しらっ亭しらっ亭
提出日時 2017-09-11 08:29:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 431 ms / 2,000 ms
コード長 896 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 42,112 KB
最終ジャッジ日時 2024-04-25 06:39:15
合計ジャッジ時間 4,573 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
10,752 KB
testcase_01 AC 25 ms
10,624 KB
testcase_02 AC 26 ms
10,752 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 AC 25 ms
10,624 KB
testcase_05 AC 26 ms
10,880 KB
testcase_06 AC 25 ms
10,752 KB
testcase_07 AC 26 ms
10,752 KB
testcase_08 AC 28 ms
10,752 KB
testcase_09 AC 26 ms
10,752 KB
testcase_10 AC 26 ms
10,624 KB
testcase_11 AC 26 ms
10,752 KB
testcase_12 AC 27 ms
10,752 KB
testcase_13 AC 27 ms
10,752 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 26 ms
10,752 KB
testcase_16 AC 26 ms
10,752 KB
testcase_17 AC 28 ms
10,624 KB
testcase_18 AC 26 ms
10,752 KB
testcase_19 AC 28 ms
10,752 KB
testcase_20 AC 27 ms
10,752 KB
testcase_21 AC 26 ms
10,624 KB
testcase_22 AC 26 ms
10,752 KB
testcase_23 AC 27 ms
10,624 KB
testcase_24 AC 28 ms
10,752 KB
testcase_25 AC 29 ms
10,752 KB
testcase_26 AC 28 ms
10,752 KB
testcase_27 AC 29 ms
10,880 KB
testcase_28 AC 28 ms
10,880 KB
testcase_29 AC 33 ms
11,264 KB
testcase_30 AC 33 ms
11,392 KB
testcase_31 AC 36 ms
11,264 KB
testcase_32 AC 43 ms
11,904 KB
testcase_33 AC 44 ms
12,160 KB
testcase_34 AC 47 ms
12,288 KB
testcase_35 AC 88 ms
15,488 KB
testcase_36 AC 89 ms
15,616 KB
testcase_37 AC 93 ms
15,744 KB
testcase_38 AC 192 ms
23,936 KB
testcase_39 AC 203 ms
24,576 KB
testcase_40 AC 208 ms
25,088 KB
testcase_41 AC 333 ms
34,560 KB
testcase_42 AC 335 ms
34,688 KB
testcase_43 AC 379 ms
38,784 KB
testcase_44 AC 431 ms
42,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7


def setup(n):
    fact = [0] * n
    revFact = [0] * n
    fact[0] = 1
    for i in range(1, n):
        fact[i] = fact[i - 1] * i % mod

    revFact[n - 1] = pow(fact[n - 1], mod - 2, mod)
    for i in range(n - 2, -1, -1):
        revFact[i] = revFact[i + 1] * (i + 1) % mod
    return fact, revFact


def solve(n):
    fact, revFact = setup(n * 2 + 1)

    def P(n, r): return fact[n] * revFact[n - r] % mod if n >= r else 0
    def C(n, r): return P(n, r) * revFact[r] % mod
    def catalan(n): return (C(2 * n, n) - C(2 * n, n + 1) + mod) % mod

    ans = 0
    m = n // 2

    for i in range(m+1):
        ans += C(n + 2 * i, i)
    ans %= mod

    csum = 0

    for i in range(1, m + 1):
        j = m - i
        csum += catalan(i - 1)
        csum %= mod
        ans += mod - C(n + 2 * j, j) * csum * 2 % mod

    return ans % mod


n = int(input())
print(solve(n))

0