結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,328 ms
117,476 KB
testcase_01 AC 1,342 ms
117,628 KB
testcase_02 AC 1,336 ms
117,980 KB
testcase_03 AC 1,333 ms
117,460 KB
testcase_04 AC 1,338 ms
117,844 KB
testcase_05 AC 1,340 ms
117,588 KB
testcase_06 AC 1,349 ms
117,504 KB
testcase_07 AC 1,339 ms
117,624 KB
testcase_08 AC 1,367 ms
117,492 KB
testcase_09 AC 1,338 ms
117,592 KB
testcase_10 AC 206 ms
100,856 KB
testcase_11 AC 345 ms
102,528 KB
testcase_12 AC 806 ms
108,744 KB
testcase_13 AC 222 ms
100,916 KB
testcase_14 AC 769 ms
108,264 KB
testcase_15 AC 204 ms
100,692 KB
testcase_16 AC 574 ms
106,416 KB
testcase_17 AC 369 ms
102,420 KB
testcase_18 AC 334 ms
102,400 KB
testcase_19 AC 222 ms
101,120 KB
testcase_20 AC 631 ms
106,556 KB
testcase_21 AC 631 ms
107,484 KB
testcase_22 AC 240 ms
101,120 KB
testcase_23 AC 516 ms
104,780 KB
testcase_24 AC 509 ms
105,076 KB
testcase_25 AC 216 ms
100,992 KB
testcase_26 AC 678 ms
107,220 KB
testcase_27 AC 586 ms
106,548 KB
testcase_28 AC 302 ms
101,596 KB
testcase_29 AC 373 ms
102,804 KB
testcase_30 AC 114 ms
83,328 KB
testcase_31 AC 121 ms
84,992 KB
testcase_32 AC 121 ms
85,248 KB
testcase_33 AC 119 ms
84,736 KB
testcase_34 AC 113 ms
82,944 KB
testcase_35 AC 112 ms
83,200 KB
testcase_36 AC 120 ms
84,864 KB
testcase_37 AC 116 ms
84,480 KB
testcase_38 AC 117 ms
83,840 KB
testcase_39 AC 117 ms
84,992 KB
testcase_40 RE -
testcase_41 RE -
testcase_42 AC 1,352 ms
117,612 KB
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
        ans%=MOD
print(ans)
0