結果

問題 No.1202 お菓子の食べ方
ユーザー hotman78hotman78
提出日時 2020-08-22 09:42:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,487 ms / 2,000 ms
コード長 1,261 bytes
コンパイル時間 954 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 118,360 KB
最終ジャッジ日時 2024-04-25 11:39:23
合計ジャッジ時間 35,505 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,386 ms
118,208 KB
testcase_01 AC 1,340 ms
118,128 KB
testcase_02 AC 1,391 ms
118,188 KB
testcase_03 AC 1,379 ms
117,696 KB
testcase_04 AC 1,329 ms
118,072 KB
testcase_05 AC 1,360 ms
117,824 KB
testcase_06 AC 1,357 ms
118,108 KB
testcase_07 AC 1,345 ms
118,244 KB
testcase_08 AC 1,333 ms
118,084 KB
testcase_09 AC 1,338 ms
118,072 KB
testcase_10 AC 203 ms
101,120 KB
testcase_11 AC 331 ms
102,792 KB
testcase_12 AC 795 ms
108,972 KB
testcase_13 AC 219 ms
101,272 KB
testcase_14 AC 775 ms
108,876 KB
testcase_15 AC 188 ms
101,120 KB
testcase_16 AC 566 ms
106,784 KB
testcase_17 AC 359 ms
102,784 KB
testcase_18 AC 352 ms
102,784 KB
testcase_19 AC 220 ms
101,512 KB
testcase_20 AC 614 ms
107,164 KB
testcase_21 AC 613 ms
107,336 KB
testcase_22 AC 248 ms
101,380 KB
testcase_23 AC 530 ms
105,260 KB
testcase_24 AC 523 ms
105,048 KB
testcase_25 AC 219 ms
101,248 KB
testcase_26 AC 684 ms
107,320 KB
testcase_27 AC 577 ms
106,912 KB
testcase_28 AC 287 ms
102,072 KB
testcase_29 AC 377 ms
103,276 KB
testcase_30 AC 113 ms
83,456 KB
testcase_31 AC 113 ms
85,248 KB
testcase_32 AC 117 ms
85,120 KB
testcase_33 AC 110 ms
85,120 KB
testcase_34 AC 117 ms
83,200 KB
testcase_35 AC 113 ms
83,456 KB
testcase_36 AC 120 ms
84,864 KB
testcase_37 AC 116 ms
85,120 KB
testcase_38 AC 115 ms
84,096 KB
testcase_39 AC 113 ms
85,120 KB
testcase_40 AC 1,351 ms
117,848 KB
testcase_41 AC 1,479 ms
117,872 KB
testcase_42 AC 1,487 ms
118,360 KB
testcase_43 AC 1,353 ms
117,976 KB
testcase_44 AC 1,365 ms
118,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD=1000000007
sz=1010101
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
        ans%=MOD
print(ans)
0