結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー LyricalMaestroLyricalMaestro
提出日時 2023-10-04 02:43:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 124 ms / 2,000 ms
コード長 1,637 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 85,760 KB
最終ジャッジ日時 2023-10-04 02:43:47
合計ジャッジ時間 6,653 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,476 KB
testcase_01 AC 70 ms
71,248 KB
testcase_02 AC 74 ms
71,372 KB
testcase_03 AC 70 ms
71,340 KB
testcase_04 AC 72 ms
71,208 KB
testcase_05 AC 71 ms
71,260 KB
testcase_06 AC 73 ms
71,204 KB
testcase_07 AC 72 ms
71,200 KB
testcase_08 AC 71 ms
71,072 KB
testcase_09 AC 71 ms
71,180 KB
testcase_10 AC 71 ms
71,476 KB
testcase_11 AC 71 ms
71,332 KB
testcase_12 AC 71 ms
71,532 KB
testcase_13 AC 71 ms
71,368 KB
testcase_14 AC 72 ms
71,088 KB
testcase_15 AC 75 ms
71,060 KB
testcase_16 AC 73 ms
71,372 KB
testcase_17 AC 73 ms
71,212 KB
testcase_18 AC 71 ms
71,336 KB
testcase_19 AC 72 ms
71,292 KB
testcase_20 AC 71 ms
71,388 KB
testcase_21 AC 73 ms
71,244 KB
testcase_22 AC 88 ms
71,136 KB
testcase_23 AC 73 ms
71,208 KB
testcase_24 AC 78 ms
76,124 KB
testcase_25 AC 77 ms
75,912 KB
testcase_26 AC 79 ms
75,724 KB
testcase_27 AC 81 ms
75,760 KB
testcase_28 AC 78 ms
76,008 KB
testcase_29 AC 85 ms
76,368 KB
testcase_30 AC 82 ms
76,284 KB
testcase_31 AC 84 ms
76,384 KB
testcase_32 AC 84 ms
76,812 KB
testcase_33 AC 87 ms
76,840 KB
testcase_34 AC 85 ms
76,620 KB
testcase_35 AC 89 ms
77,884 KB
testcase_36 AC 92 ms
77,848 KB
testcase_37 AC 90 ms
77,944 KB
testcase_38 AC 103 ms
80,140 KB
testcase_39 AC 102 ms
80,536 KB
testcase_40 AC 101 ms
80,700 KB
testcase_41 AC 113 ms
83,592 KB
testcase_42 AC 113 ms
83,432 KB
testcase_43 AC 124 ms
84,872 KB
testcase_44 AC 118 ms
85,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7



class CombinationCalculator:
    """
    modを考慮したPermutation, Combinationを計算するためのクラス
    """    
    def __init__(self, size, mod):
        self.mod = mod
        self.factorial = [0] * (size + 1)
        self.factorial[0] = 1
        for i in range(1, size + 1):
            self.factorial[i] = (i * self.factorial[i - 1]) % self.mod
        
        self.inv_factorial = [0] * (size + 1)
        self.inv_factorial[size] = pow(self.factorial[size], self.mod - 2, self.mod)

        for i in reversed(range(size)):
            self.inv_factorial[i] = ((i + 1) * self.inv_factorial[i + 1]) % self.mod

    def calc_combination(self, n, r):
        if n < 0 or n < r:
            return 0

        if r == 0 or n == r:
            return 1
        
        ans = self.inv_factorial[n - r] * self.inv_factorial[r]
        ans %= self.mod
        ans *= self.factorial[n]
        ans %= self.mod
        return ans
    
    def calc_permutation(self, n, r):
        if n < 0 or n < r:
            return 0

        ans = self.inv_factorial[n - r]
        ans *= self.factorial[n]
        ans %= self.mod
        return ans
        

def main():
    N = int(input())

    combi = CombinationCalculator(3 * N, MOD)

    answer = 1
    l = 1
    while l * 2 + N <= 2 * N:
        total = combi.calc_combination(N + 2 * l - 1, l)
        # (-N, N ) -> (l, N + l - 1)
        cataran = combi.calc_combination(N + 2 * l - 1, N + l)
        t = total - cataran
        t %= MOD
        answer += t
        answer %= MOD
        l += 1
    print(answer)



if __name__ == "__main__":
    main()
0