結果

問題 No.1202 お菓子の食べ方
ユーザー hotman78hotman78
提出日時 2020-08-22 09:38:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,244 bytes
コンパイル時間 812 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 118,260 KB
最終ジャッジ日時 2024-04-25 11:38:12
合計ジャッジ時間 29,753 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 112 ms
83,328 KB
testcase_31 AC 114 ms
85,120 KB
testcase_32 AC 116 ms
84,992 KB
testcase_33 AC 116 ms
84,864 KB
testcase_34 AC 109 ms
83,200 KB
testcase_35 AC 109 ms
83,200 KB
testcase_36 AC 114 ms
84,864 KB
testcase_37 AC 111 ms
84,608 KB
testcase_38 AC 114 ms
83,840 KB
testcase_39 AC 110 ms
84,864 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 WA -
testcase_43 RE -
testcase_44 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD=1000000007
sz=1000000
table=[1]*sz
inv=[1]*sz
inv_table=[1]*sz
for i in range(2,sz):
    table[i]=table[i-1]*i%MOD
for i in range(2,sz):
    inv[i]=(MOD-inv[MOD%i]*(MOD//i))%MOD
for i in range(2,sz):
    inv_table[i]=inv_table[i-1]*inv[i]%MOD

def comb(i,j):
    if i<j:
        return 0
    if i<0 or j<0:
        return 0
    return table[i]*inv_table[j]*inv_table[i-j]%MOD

def mod_inv(a):
    b=MOD-2
    ret=1
    while b:
        if b%2==1:
            ret=ret*a%MOD
        a=a*a%MOD
        b//=2
    return ret
import math
n,m=list(map(int,input().split()))
v=[[0]*m for x in range(n)]
assert(1<=n and n<=1000)
assert(1<=m and m<=1000)
for i in range(n):
    v[i]=list(map(int,input().split()))

ans=0
for i in range(n):
    for j in range(m):
        tmp=0
        tmp+=comb(i+j+v[i][j]-1,v[i][j]-1)
        if(i!=n-1):
            tmp+=(comb(i+j+v[i][j],i+j)*v[i][j]-comb(i+j+v[i+1][j],i+j)*v[i+1][j])*mod_inv(i+j+1)
        else:
            tmp+=comb(i+j+v[i][j],i+j)*v[i][j]*mod_inv(i+j+1)
        if j!=m-1:
            tmp+=(comb(i+j+v[i][j],i+j)*v[i][j]-comb(i+j+v[i][j+1],i+j)*v[i][j+1])*mod_inv(i+j+1)
        else:
            tmp+=comb(i+j+v[i][j],i+j)*v[i][j]*mod_inv(i+j+1)
        ans+=tmp*comb(i+j,i)%MOD
print(ans)
0