結果
問題 | No.1141 田グリッド |
ユーザー | brthyyjp |
提出日時 | 2021-03-20 14:43:42 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,472 bytes |
コンパイル時間 | 268 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 96,048 KB |
最終ジャッジ日時 | 2024-11-21 00:23:14 |
合計ジャッジ時間 | 8,293 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
54,552 KB |
testcase_01 | AC | 44 ms
54,732 KB |
testcase_02 | AC | 42 ms
54,984 KB |
testcase_03 | AC | 43 ms
54,644 KB |
testcase_04 | AC | 44 ms
55,352 KB |
testcase_05 | AC | 44 ms
55,824 KB |
testcase_06 | AC | 43 ms
54,508 KB |
testcase_07 | AC | 43 ms
55,236 KB |
testcase_08 | AC | 75 ms
73,900 KB |
testcase_09 | AC | 64 ms
69,852 KB |
testcase_10 | AC | 71 ms
73,288 KB |
testcase_11 | AC | 71 ms
72,028 KB |
testcase_12 | AC | 69 ms
73,552 KB |
testcase_13 | AC | 578 ms
92,420 KB |
testcase_14 | AC | 598 ms
96,048 KB |
testcase_15 | AC | 578 ms
84,164 KB |
testcase_16 | AC | 565 ms
84,712 KB |
testcase_17 | AC | 563 ms
84,440 KB |
testcase_18 | AC | 87 ms
78,840 KB |
testcase_19 | AC | 86 ms
78,828 KB |
testcase_20 | AC | 88 ms
79,312 KB |
testcase_21 | AC | 575 ms
84,740 KB |
testcase_22 | AC | 573 ms
84,336 KB |
testcase_23 | AC | 567 ms
84,356 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | AC | 99 ms
79,064 KB |
testcase_30 | AC | 104 ms
79,220 KB |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline h, w = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(h)] mod = 1000000007 from collections import defaultdict flag = False zr = set() zc = set() for i in range(h): for j in range(w): if A[i][j] == 0: flag = True zr.add(i) zc.add(j) if not flag: X = [[1]*(w+1) for i in range(h+1)] for i in range(h): for j in range(w): X[i+1][j+1] = X[i+1][j]*X[i][j+1]*pow(X[i][j],mod-2,mod)*A[i][j] X[i+1][j+1] %= mod def rect(r1, c1, r2, c2): res = X[r2][c2]*pow(X[r2][c1],mod-2, mod)*pow(X[r1][c2],mod-2, mod)*X[r1][c1] return res%mod #print(X) #print(X[h][w]%mod) q = int(input()) for i in range(q): r, c = map(int, input().split()) r, c = r-1, c-1 ans = rect(r+1, c+1, h, w)*rect(0, c+1, r, w)*rect(r+1, 0, h, c)*rect(0, 0, r, c) #print(rect(r+1, c+1, h, w), rect(0, c+1, r, w), rect(r+1, 0, h, c), rect(0, 0, r, c)) print(ans%mod) else: if len(zr) >= 2 and len(zc) >= 2: q = int(input()) for i in range(q): r, c = map(int, input().split()) r, c = r-1, c-1 print(0) elif len(zr) == 1: total = 1 d = defaultdict(lambda: 1) for i in range(h): for j in range(w): if i in zr: continue d[j] *= A[i][j] d[j] %= mod total *= A[i][j] total %= mod q = int(input()) for i in range(q): r, c = map(int, input().split()) r, c = r-1, c-1 if r in zr: ans = total*pow(d[c], mod-2, mod) print(ans%mod) else: print(0) elif len(zc) == 1: total = 1 d = defaultdict(lambda: 1) for i in range(h): for j in range(w): if j in zc: continue d[i] *= A[i][j] d[i] %= mod total *= A[i][j] total %= mod q = int(input()) for i in range(q): r, c = map(int, input().split()) r, c = r-1, c-1 if c in zc: ans = total*pow(d[r], mod-2, mod) print(ans%mod) else: print(0)