結果
問題 |
No.1141 田グリッド
|
ユーザー |
![]() |
提出日時 | 2020-08-01 21:55:35 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 691 ms / 2,000 ms |
コード長 | 905 bytes |
コンパイル時間 | 131 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 26,112 KB |
最終ジャッジ日時 | 2024-07-08 08:37:59 |
合計ジャッジ時間 | 12,033 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] Q = int(input()) m = 1000000007 total = 1 rows = [1] * H cols = [1] * W total0 = 0 rows0 = [0] * H cols0 = [0] * W for i in range(H): for j in range(W): x = A[i][j] if x == 0: total0 += 1 rows0[i] += 1 cols0[j] += 1 else: total *= x total %= m rows[i] *= x rows[i] %= m cols[j] *= x cols[j] %= m result = [] for _ in range(Q): r, c = map(lambda x: int(x) - 1, input().split()) x = A[r][c] t = total0 - rows0[r] - cols0[c] if x == 0: t += 1 if t > 0: result.append(0) continue t = total * pow(rows[r], -1, m) % m * pow(cols[c], -1, m) % m if x != 0: t *= x t %= m result.append(t) print(*result, sep='\n')