結果

問題 No.906 Y字グラフ
ユーザー convexineqconvexineq
提出日時 2021-05-05 09:16:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 76,476 KB
最終ジャッジ日時 2023-10-10 01:04:05
合計ジャッジ時間 4,911 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,236 KB
testcase_01 AC 70 ms
71,368 KB
testcase_02 AC 75 ms
71,312 KB
testcase_03 AC 77 ms
76,208 KB
testcase_04 AC 74 ms
75,812 KB
testcase_05 AC 76 ms
75,488 KB
testcase_06 AC 73 ms
75,784 KB
testcase_07 AC 77 ms
76,120 KB
testcase_08 AC 75 ms
75,596 KB
testcase_09 AC 75 ms
76,132 KB
testcase_10 AC 76 ms
75,856 KB
testcase_11 AC 76 ms
75,808 KB
testcase_12 AC 78 ms
75,816 KB
testcase_13 AC 78 ms
75,856 KB
testcase_14 AC 77 ms
75,812 KB
testcase_15 AC 78 ms
75,952 KB
testcase_16 AC 78 ms
76,476 KB
testcase_17 AC 78 ms
75,720 KB
testcase_18 AC 77 ms
76,368 KB
testcase_19 AC 79 ms
76,144 KB
testcase_20 AC 77 ms
75,760 KB
testcase_21 AC 78 ms
75,724 KB
testcase_22 AC 79 ms
76,076 KB
testcase_23 AC 80 ms
76,156 KB
testcase_24 AC 82 ms
76,296 KB
testcase_25 AC 80 ms
76,100 KB
testcase_26 AC 82 ms
76,088 KB
testcase_27 AC 83 ms
76,260 KB
testcase_28 AC 86 ms
76,088 KB
testcase_29 AC 88 ms
76,276 KB
testcase_30 AC 88 ms
76,124 KB
testcase_31 AC 88 ms
76,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def polymul(f,g):
    lf = len(f)
    lg = len(g)
    res = [0]*(lf+lg-1)
    for i in range(lf):
        for j in range(lg):
            res[i+j] += f[i]*g[j]
            res[i+j] %= MOD
    return res

def fps_nth_term(f,g,N):
    assert g[0] != 0
    while N:
        h = g[:]
        for i in range(1,len(g),2):
            h[i] = -h[i]
        f = polymul(f,h)[N%2:N+1:2]
        g = polymul(g,h)[:N+1:2]
        N //= 2
    return f[0]*pow(g[0],MOD-2,MOD)%MOD

def g(lst):
    v = [1]
    for c in lst:
        v = polymul(v,[1]+[0]*(c-1)+[-1])
    return v

MOD = 10**9+7
N = int(input())-4
ans = 0
#a<b<c
if N >= 3: ans += fps_nth_term([1],g([3,2,1]),N-3)
#a=b<c
if N >= 1: ans += fps_nth_term([1],g([3,1]),N-1)
#a<b=c
if N >= 2: ans += fps_nth_term([1],g([3,2]),N-2)
#a=b=c
ans += int(N%3==0)
print(ans%MOD)
0