結果

問題 No.1141 田グリッド
ユーザー simansiman
提出日時 2022-07-25 08:19:02
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 636 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 11,280 KB
実行使用メモリ 24,356 KB
最終ジャッジ日時 2023-09-21 11:08:45
合計ジャッジ時間 11,001 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,112 KB
testcase_01 AC 76 ms
15,108 KB
testcase_02 AC 76 ms
15,100 KB
testcase_03 AC 77 ms
15,224 KB
testcase_04 AC 78 ms
15,108 KB
testcase_05 AC 76 ms
15,088 KB
testcase_06 AC 75 ms
15,144 KB
testcase_07 AC 76 ms
15,160 KB
testcase_08 AC 81 ms
15,172 KB
testcase_09 AC 79 ms
15,084 KB
testcase_10 AC 82 ms
15,068 KB
testcase_11 AC 83 ms
15,248 KB
testcase_12 AC 82 ms
15,156 KB
testcase_13 AC 361 ms
24,356 KB
testcase_14 AC 425 ms
19,616 KB
testcase_15 AC 358 ms
16,248 KB
testcase_16 AC 361 ms
16,184 KB
testcase_17 AC 366 ms
16,216 KB
testcase_18 AC 318 ms
16,160 KB
testcase_19 AC 315 ms
16,188 KB
testcase_20 AC 319 ms
16,240 KB
testcase_21 AC 356 ms
16,264 KB
testcase_22 AC 365 ms
16,468 KB
testcase_23 AC 358 ms
16,336 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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 = []

all = 1

H.times do |i|
  W.times do |j|
    all *= A[i][j]
    all %= MOD
  end
end

H.times do |i|
  row = 1

  W.times do |j|
    row *= A[i][j]
    row %= MOD
  end

  R << row
end

C = []

W.times do |j|
  col = 1

  H.times do |i|
    col *= A[i][j]
    col %= MOD
  end

  C << col
end

Q = gets.to_i
Q.times do
  r, c = gets.split.map(&:to_i)

  ans = (all * R[r - 1].mod_inverse(MOD) * C[c - 1].mod_inverse(MOD) * A[r - 1][c - 1]) % MOD

  puts ans
end
0