結果
問題 | No.1141 田グリッド |
ユーザー | kimiyuki |
提出日時 | 2020-07-31 21:52:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 675 ms / 2,000 ms |
コード長 | 1,740 bytes |
コンパイル時間 | 256 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 32,296 KB |
最終ジャッジ日時 | 2024-07-06 17:46:30 |
合計ジャッジ時間 | 15,223 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 42 ms
11,520 KB |
testcase_01 | AC | 38 ms
11,520 KB |
testcase_02 | AC | 37 ms
11,392 KB |
testcase_03 | AC | 38 ms
11,520 KB |
testcase_04 | AC | 38 ms
11,648 KB |
testcase_05 | AC | 37 ms
11,520 KB |
testcase_06 | AC | 38 ms
11,520 KB |
testcase_07 | AC | 38 ms
11,392 KB |
testcase_08 | AC | 43 ms
12,416 KB |
testcase_09 | AC | 40 ms
11,904 KB |
testcase_10 | AC | 44 ms
12,416 KB |
testcase_11 | AC | 45 ms
12,544 KB |
testcase_12 | AC | 43 ms
12,288 KB |
testcase_13 | AC | 623 ms
27,944 KB |
testcase_14 | AC | 675 ms
32,296 KB |
testcase_15 | AC | 603 ms
29,608 KB |
testcase_16 | AC | 605 ms
29,696 KB |
testcase_17 | AC | 608 ms
29,660 KB |
testcase_18 | AC | 606 ms
29,916 KB |
testcase_19 | AC | 611 ms
29,588 KB |
testcase_20 | AC | 600 ms
29,580 KB |
testcase_21 | AC | 605 ms
29,392 KB |
testcase_22 | AC | 607 ms
29,384 KB |
testcase_23 | AC | 609 ms
29,384 KB |
testcase_24 | AC | 605 ms
29,232 KB |
testcase_25 | AC | 609 ms
29,560 KB |
testcase_26 | AC | 602 ms
29,964 KB |
testcase_27 | AC | 609 ms
29,816 KB |
testcase_28 | AC | 608 ms
29,660 KB |
testcase_29 | AC | 600 ms
29,232 KB |
testcase_30 | AC | 607 ms
29,780 KB |
testcase_31 | AC | 609 ms
29,460 KB |
testcase_32 | AC | 604 ms
29,516 KB |
testcase_33 | AC | 602 ms
29,388 KB |
ソースコード
#!/usr/bin/env python3 from typing import * MOD = 1000000007 def solve(h: int, w: int, a: List[List[int]], q: int, r: List[int], c: List[int]) -> List[int]: all_prod = 1 all_zero = 0 row_prod = [1] * h col_prod = [1] * w row_zero = [0] * h col_zero = [0] * w for y in range(h): for x in range(w): if a[y][x] == 0: row_zero[y] += 1 col_zero[x] += 1 else: row_prod[y] = row_prod[y] * a[y][x] % MOD col_prod[x] = col_prod[x] * a[y][x] % MOD all_prod = all_prod * row_prod[y] % MOD all_zero += row_zero[y] ans = [] for y, x in zip(r, c): prod = all_prod * pow(row_prod[y], MOD - 2, MOD) * pow(col_prod[x], MOD - 2, MOD) zero = all_zero - row_zero[y] - col_zero[x] if a[y][x] == 0: zero += 1 else: prod *= a[y][x] prod %= MOD if zero: ans.append(0) else: ans.append(prod) return ans # generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator) def main(): import sys tokens = iter(sys.stdin.read().split()) H = int(next(tokens)) W = int(next(tokens)) A = [[None for _ in range(W)] for _ in range(H)] for j in range(H): for i in range(W): A[j][i] = int(next(tokens)) Q = int(next(tokens)) r = [None for _ in range(Q)] c = [None for _ in range(Q)] for i in range(Q): r[i] = int(next(tokens)) - 1 c[i] = int(next(tokens)) - 1 assert next(tokens, None) is None ans = solve(H, W, A, Q, r, c) print(*ans, sep='\n') if __name__ == '__main__': main()