結果
| 問題 |
No.1141 田グリッド
|
| ユーザー |
siman
|
| 提出日時 | 2022-07-25 09:07:56 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 394 ms / 2,000 ms |
| コード長 | 927 bytes |
| コンパイル時間 | 137 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 18,272 KB |
| 最終ジャッジ日時 | 2024-07-07 05:58:03 |
| 合計ジャッジ時間 | 10,380 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 |
コンパイルメッセージ
Syntax OK
ソースコード
class Integer
def mod_inverse(mod)
self.pow(mod - 2, mod)
end
end
H, W = gets.split.map(&:to_i)
A = H.times.map { gets.split.map(&:to_i) }
MOD = 10 ** 9 + 7
R = []
zero_cnt = 0
ZR = Array.new(H, 0)
ZC = Array.new(W, 0)
all = 1
H.times do |i|
W.times do |j|
all *= [1, A[i][j]].max
all %= MOD
if A[i][j] == 0
ZR[i] += 1
ZC[j] += 1
zero_cnt += 1
end
end
end
H.times do |i|
row = 1
W.times do |j|
row *= [1, A[i][j]].max
row %= MOD
end
R << row
end
C = []
W.times do |j|
col = 1
H.times do |i|
col *= [1, A[i][j]].max
col %= MOD
end
C << col
end
Q = gets.to_i
Q.times do
r, c = gets.split.map(&:to_i)
ans = all
ans *= R[r - 1].mod_inverse(MOD) * C[c - 1].mod_inverse(MOD) * [1, A[r - 1][c - 1]].max
zc = zero_cnt - ZR[r - 1] - ZC[c - 1]
zc += 1 if A[r - 1][c - 1] == 0
if zc > 0
puts 0
else
puts ans % MOD
end
end
siman