結果
問題 | No.1141 田グリッド |
ユーザー | brthyyjp |
提出日時 | 2021-03-20 14:41:50 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,472 bytes |
コンパイル時間 | 245 ms |
コンパイル使用メモリ | 82,544 KB |
実行使用メモリ | 95,932 KB |
最終ジャッジ日時 | 2024-11-20 23:56:49 |
合計ジャッジ時間 | 8,593 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
54,596 KB |
testcase_01 | AC | 45 ms
54,244 KB |
testcase_02 | AC | 48 ms
55,940 KB |
testcase_03 | AC | 47 ms
55,328 KB |
testcase_04 | AC | 47 ms
55,452 KB |
testcase_05 | AC | 47 ms
55,248 KB |
testcase_06 | AC | 46 ms
54,708 KB |
testcase_07 | AC | 45 ms
54,360 KB |
testcase_08 | AC | 78 ms
73,272 KB |
testcase_09 | AC | 67 ms
69,496 KB |
testcase_10 | AC | 75 ms
73,496 KB |
testcase_11 | AC | 71 ms
71,792 KB |
testcase_12 | AC | 74 ms
72,756 KB |
testcase_13 | AC | 599 ms
92,492 KB |
testcase_14 | AC | 600 ms
95,932 KB |
testcase_15 | AC | 590 ms
84,416 KB |
testcase_16 | AC | 593 ms
84,732 KB |
testcase_17 | AC | 591 ms
84,568 KB |
testcase_18 | AC | 87 ms
79,352 KB |
testcase_19 | AC | 90 ms
78,944 KB |
testcase_20 | AC | 88 ms
78,964 KB |
testcase_21 | AC | 586 ms
84,360 KB |
testcase_22 | AC | 589 ms
84,348 KB |
testcase_23 | AC | 581 ms
84,560 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 104 ms
79,096 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 i 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)