結果

問題 No.660 家を通り過ぎないランダムウォーク問題
ユーザー shotoyooshotoyoo
提出日時 2021-06-19 17:36:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,101 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 85,908 KB
最終ジャッジ日時 2023-09-05 01:03:26
合計ジャッジ時間 6,473 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,164 KB
testcase_01 AC 69 ms
71,320 KB
testcase_02 AC 72 ms
71,508 KB
testcase_03 AC 73 ms
71,520 KB
testcase_04 AC 71 ms
71,348 KB
testcase_05 AC 72 ms
71,180 KB
testcase_06 AC 71 ms
71,404 KB
testcase_07 AC 71 ms
71,420 KB
testcase_08 AC 71 ms
71,544 KB
testcase_09 AC 72 ms
71,440 KB
testcase_10 AC 72 ms
71,332 KB
testcase_11 AC 71 ms
71,352 KB
testcase_12 AC 71 ms
71,384 KB
testcase_13 AC 74 ms
71,620 KB
testcase_14 AC 72 ms
71,172 KB
testcase_15 AC 72 ms
71,588 KB
testcase_16 AC 72 ms
71,464 KB
testcase_17 AC 72 ms
71,492 KB
testcase_18 AC 72 ms
71,444 KB
testcase_19 AC 70 ms
71,280 KB
testcase_20 AC 72 ms
71,308 KB
testcase_21 AC 73 ms
71,324 KB
testcase_22 AC 72 ms
71,640 KB
testcase_23 AC 73 ms
71,324 KB
testcase_24 AC 73 ms
71,172 KB
testcase_25 AC 74 ms
71,332 KB
testcase_26 AC 77 ms
76,088 KB
testcase_27 AC 76 ms
76,140 KB
testcase_28 AC 75 ms
76,032 KB
testcase_29 AC 83 ms
76,456 KB
testcase_30 AC 83 ms
76,308 KB
testcase_31 AC 86 ms
76,444 KB
testcase_32 AC 86 ms
76,344 KB
testcase_33 AC 87 ms
76,864 KB
testcase_34 AC 86 ms
76,836 KB
testcase_35 AC 87 ms
77,864 KB
testcase_36 AC 86 ms
77,928 KB
testcase_37 AC 86 ms
77,884 KB
testcase_38 AC 93 ms
80,164 KB
testcase_39 AC 92 ms
80,564 KB
testcase_40 AC 96 ms
80,568 KB
testcase_41 AC 101 ms
83,500 KB
testcase_42 AC 102 ms
83,640 KB
testcase_43 AC 106 ms
84,856 KB
testcase_44 AC 108 ms
85,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()

sys.setrecursionlimit(2*10**5+10)
write = lambda x: sys.stdout.write(x+"\n")
debug = lambda x: sys.stderr.write(x+"\n")
writef = lambda x: print("{:.12f}".format(x))


n = int(input())
M = 10**9+7
### 素数の逆元とCombination

N = 2*n+10 # 必要なテーブルサイズ
g1 = [0] * (N+1) # 元テーブル
g2 = [0] * (N+1) #逆元テーブル
inverse = [0] * (N+1) #逆元テーブル計算用テーブル
g1[0] = g1[1] = g2[0] = g2[1] = 1
inverse[0], inverse[1] = [0, 1] 
for i in range( 2, N + 1 ):
    g1[i] = ( g1[i-1] * i ) % M 
    inverse[i] = ( -inverse[M % i] * (M//i) ) % M # ai+b==0 mod M <=> i==-b*a^(-1) <=> i^(-1)==-b^(-1)*aより
    g2[i] = (g2[i-1] * inverse[i]) % M 
def cmb(n, r, M=M):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return ((g1[n] * g2[r] % M) * g2[n-r]) % M
def perm(n, r, M=M):
    if (r<0 or r>n):
        return 0
    return (g1[n] * g2[n-r]) % M
ans = 0
for i in range(n+1):
    if n+2*i>2*n:
        break
    ans += cmb(n+2*i-1, i) - cmb(n+2*i-1, i-1)
    ans %= M
print(ans%M)
0