結果

問題 No.93 ペガサス
ユーザー yaoshimaxyaoshimax
提出日時 2015-03-04 01:03:51
言語 PyPy2
(7.3.15)
結果
AC  
実行時間 961 ms / 5,000 ms
コード長 2,564 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 77,752 KB
実行使用メモリ 326,512 KB
最終ジャッジ日時 2023-09-06 06:40:48
合計ジャッジ時間 7,567 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
76,504 KB
testcase_01 AC 72 ms
76,656 KB
testcase_02 AC 73 ms
76,244 KB
testcase_03 AC 72 ms
76,336 KB
testcase_04 AC 255 ms
117,148 KB
testcase_05 AC 154 ms
92,084 KB
testcase_06 AC 138 ms
89,420 KB
testcase_07 AC 534 ms
215,696 KB
testcase_08 AC 321 ms
143,412 KB
testcase_09 AC 937 ms
320,836 KB
testcase_10 AC 110 ms
80,436 KB
testcase_11 AC 129 ms
84,848 KB
testcase_12 AC 746 ms
279,740 KB
testcase_13 AC 296 ms
136,144 KB
testcase_14 AC 181 ms
100,848 KB
testcase_15 AC 651 ms
256,376 KB
testcase_16 AC 199 ms
104,224 KB
testcase_17 AC 74 ms
76,452 KB
testcase_18 AC 74 ms
76,456 KB
testcase_19 AC 961 ms
326,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(raw_input())
mod=1000000007
dp=[[[[0 for i in range(2)] for j in range(2)] for k in range(N+1)] for l in range(N+2)]
dp[1][0][0][0]=1
dp[2][0][0][0]=2

for i in range(2,N+1):
    for j in range(N+1):
        #if dp[i][j][0][0] >0 or dp[i][j][0][1] > 0 or dp[i][j][1][0]>0 or dp[i][j][1][1]>0:
        #    print i,j, dp[i][j][0][0], dp[i][j][0][1],dp[i][j][1][0],dp[i][j][1][1]
        if dp[i][j][0][0]>0:
            dp[i+1][j][0][0]+=(i-1-j)*dp[i][j][0][0]
            dp[i+1][j][0][0]%=mod
            dp[i+1][j][0][1]+=2*dp[i][j][0][0]
            dp[i+1][j][0][1]%=mod
            if j-1>=0:
                dp[i+1][j-1][0][0]+=j*dp[i][j][0][0]
                dp[i+1][j-1][0][0]%=mod
        if dp[i][j][0][1]>0: # (i) (i-2) is adjacent, (i-1) (i-3) is not. insert i+1 in i+1 different positions
            dp[i+1][j][1][0]+=(i-2-j)*dp[i][j][0][1]
            dp[i+1][j][1][0]%=mod
            dp[i+1][j][1][1]+=2*dp[i][j][0][1] # next to (i-1), both side
            dp[i+1][j][1][1]%=mod # next to (i-1), both side
            dp[i+1][j][0][0]+=dp[i][j][0][1] # between (i) and (i-2)
            dp[i+1][j][0][0]%=mod # between (i) and (i-2)
            if j-1>=0:
                dp[i+1][j-1][1][0]+=j*dp[i][j][0][1]
                dp[i+1][j-1][1][0]%=mod
        if dp[i][j][1][0]>0: # (i-1) (i-3) is adjacent, (i) (i-2) is not, insert i+1 
            dp[i+1][j+1][0][0]+=(i-1-j)*dp[i][j][1][0]
            dp[i+1][j+1][0][0]%=mod
            dp[i+1][j+1][0][1]+=dp[i][j][1][0] # next to (i-1), opposite of (i-3)
            dp[i+1][j+1][0][1]%=mod # next to (i-1), opposite of (i-3)
            dp[i+1][j][0][1]+=dp[i][j][1][0] # between (i-1) and (i-3)
            dp[i+1][j][0][1]%=mod # between (i-1) and (i-3)
            if j-1>=0:
                dp[i+1][j][0][0]+=j*dp[i][j][1][0]
                dp[i+1][j][0][0]%=mod
        if dp[i][j][1][1]>0: # (i-1) (i-3) is adjacent, (i)(i-2) is adjacent
            dp[i+1][j+1][1][0]+=(i-2-j)*dp[i][j][1][1]
            dp[i+1][j+1][1][0]%=mod
            dp[i+1][j+1][1][1]+=dp[i][j][1][1] # next to (i-1), opposite of (i-3)
            dp[i+1][j+1][1][1]%=mod # next to (i-1), opposite of (i-3)
            dp[i+1][j][1][1]+=dp[i][j][1][1] # between (i-1) and (i-3)
            dp[i+1][j][1][1]%=mod # between (i-1) and (i-3)
            dp[i+1][j+1][0][0]+=dp[i][j][1][1] # between (i) and (i-2)
            dp[i+1][j+1][0][0]%=mod # between (i) and (i-2)
            if j-1>=0:
                dp[i+1][j][1][0]+=j*dp[i][j][1][1]
                dp[i+1][j][1][0]%=mod
print dp[N][0][0][0]

0