結果

問題 No.1141 田グリッド
ユーザー qumazakiqumazaki
提出日時 2020-09-08 18:02:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 213 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 1,067 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 112,156 KB
最終ジャッジ日時 2023-08-20 02:35:53
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,152 KB
testcase_01 AC 64 ms
71,068 KB
testcase_02 AC 64 ms
71,220 KB
testcase_03 AC 64 ms
71,236 KB
testcase_04 AC 63 ms
70,968 KB
testcase_05 AC 64 ms
71,132 KB
testcase_06 AC 63 ms
71,164 KB
testcase_07 AC 65 ms
71,032 KB
testcase_08 AC 71 ms
76,488 KB
testcase_09 AC 72 ms
76,416 KB
testcase_10 AC 72 ms
76,304 KB
testcase_11 AC 71 ms
76,544 KB
testcase_12 AC 72 ms
76,212 KB
testcase_13 AC 213 ms
110,432 KB
testcase_14 AC 191 ms
109,928 KB
testcase_15 AC 188 ms
109,516 KB
testcase_16 AC 187 ms
109,756 KB
testcase_17 AC 183 ms
109,560 KB
testcase_18 AC 112 ms
112,156 KB
testcase_19 AC 114 ms
109,280 KB
testcase_20 AC 113 ms
112,096 KB
testcase_21 AC 185 ms
109,792 KB
testcase_22 AC 188 ms
109,660 KB
testcase_23 AC 186 ms
109,796 KB
testcase_24 AC 119 ms
109,420 KB
testcase_25 AC 121 ms
109,468 KB
testcase_26 AC 122 ms
109,748 KB
testcase_27 AC 121 ms
109,432 KB
testcase_28 AC 121 ms
109,420 KB
testcase_29 AC 116 ms
109,664 KB
testcase_30 AC 116 ms
109,472 KB
testcase_31 AC 119 ms
109,556 KB
testcase_32 AC 115 ms
109,440 KB
testcase_33 AC 113 ms
109,464 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)
    ans_i %= mod
    if(a[r*w+c] != 0):
        ans_i *= a[r*w+c]
        ans_i %= mod
    ans.append(ans_i)

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