結果

問題 No.1141 田グリッド
ユーザー qumazakiqumazaki
提出日時 2020-09-08 17:57:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 992 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 112,152 KB
最終ジャッジ日時 2023-08-20 02:25:56
合計ジャッジ時間 8,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,084 KB
testcase_01 AC 72 ms
71,200 KB
testcase_02 AC 73 ms
71,256 KB
testcase_03 AC 74 ms
71,136 KB
testcase_04 AC 74 ms
71,196 KB
testcase_05 AC 73 ms
70,728 KB
testcase_06 AC 75 ms
71,260 KB
testcase_07 AC 76 ms
71,092 KB
testcase_08 AC 85 ms
76,612 KB
testcase_09 AC 85 ms
76,336 KB
testcase_10 AC 84 ms
76,480 KB
testcase_11 AC 83 ms
76,456 KB
testcase_12 AC 84 ms
76,440 KB
testcase_13 AC 245 ms
110,376 KB
testcase_14 AC 213 ms
109,968 KB
testcase_15 AC 213 ms
109,492 KB
testcase_16 AC 212 ms
109,580 KB
testcase_17 AC 215 ms
109,628 KB
testcase_18 AC 132 ms
112,152 KB
testcase_19 AC 131 ms
109,192 KB
testcase_20 AC 130 ms
112,148 KB
testcase_21 AC 212 ms
109,708 KB
testcase_22 AC 211 ms
109,656 KB
testcase_23 AC 211 ms
109,332 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 135 ms
109,556 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 131 ms
109,392 KB
testcase_33 AC 129 ms
109,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

h,w = list(map(int,readline().split()))
data = list(map(int,read().split()))
a = data[:h*w]
q = data[h*w]
rc = data[h*w+1:]
mod = 10**9+7

cnt0 = 0
tot = 1
cnt0_h = [0]*h
cnt0_w = [0]*w
tot_h = [1]*h
tot_w = [1]*w
for i in range(h):
    for j in range(w):
        aij = a[i*w+j]
        if(aij==0):
            cnt0 += 1
            cnt0_h[i] += 1
            cnt0_w[j] += 1
        else:
            tot *= aij
            tot %= mod
            tot_h[i] *= aij
            tot_h[i] %= mod
            tot_w[j] *= aij
            tot_w[j] %= mod

ans =[]
it = iter(rc)
for r,c in zip(it,it):
    r -= 1
    c -= 1
    num0 = cnt0 - cnt0_h[r] - cnt0_w[c] + (a[r*w+c]==0)
    if(num0>0):
        ans.append(0)
        continue
    ans_i = tot * pow(tot_h[r],mod-2,mod) * pow(tot_w[c],mod-2,mod) * a[r*w+c]
    ans_i %= mod
    ans.append(ans_i)

print('\n'.join(map(str,ans)))
0