結果
問題 | No.1141 田グリッド |
ユーザー | terasa |
提出日時 | 2022-05-30 20:40:55 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 441 ms / 2,000 ms |
コード長 | 2,303 bytes |
コンパイル時間 | 217 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 98,816 KB |
最終ジャッジ日時 | 2024-09-21 00:54:19 |
合計ジャッジ時間 | 8,019 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
54,784 KB |
testcase_01 | AC | 53 ms
55,296 KB |
testcase_02 | AC | 53 ms
55,168 KB |
testcase_03 | AC | 49 ms
55,552 KB |
testcase_04 | AC | 48 ms
55,680 KB |
testcase_05 | AC | 48 ms
55,168 KB |
testcase_06 | AC | 48 ms
54,784 KB |
testcase_07 | AC | 49 ms
55,168 KB |
testcase_08 | AC | 82 ms
73,728 KB |
testcase_09 | AC | 78 ms
70,400 KB |
testcase_10 | AC | 83 ms
73,984 KB |
testcase_11 | AC | 77 ms
70,656 KB |
testcase_12 | AC | 97 ms
77,440 KB |
testcase_13 | AC | 296 ms
89,984 KB |
testcase_14 | AC | 441 ms
98,816 KB |
testcase_15 | AC | 302 ms
82,048 KB |
testcase_16 | AC | 305 ms
81,408 KB |
testcase_17 | AC | 311 ms
82,048 KB |
testcase_18 | AC | 207 ms
83,968 KB |
testcase_19 | AC | 207 ms
83,328 KB |
testcase_20 | AC | 205 ms
83,712 KB |
testcase_21 | AC | 296 ms
81,280 KB |
testcase_22 | AC | 294 ms
81,408 KB |
testcase_23 | AC | 297 ms
81,408 KB |
testcase_24 | AC | 212 ms
83,328 KB |
testcase_25 | AC | 210 ms
84,096 KB |
testcase_26 | AC | 219 ms
83,584 KB |
testcase_27 | AC | 242 ms
83,968 KB |
testcase_28 | AC | 204 ms
82,944 KB |
testcase_29 | AC | 206 ms
83,200 KB |
testcase_30 | AC | 217 ms
84,224 KB |
testcase_31 | AC | 202 ms
83,840 KB |
testcase_32 | AC | 203 ms
83,328 KB |
testcase_33 | AC | 204 ms
83,200 KB |
ソースコード
import sys import pypyjit import itertools import heapq import math from collections import deque, defaultdict import bisect input = sys.stdin.readline sys.setrecursionlimit(10 ** 6) pypyjit.set_param('max_unroll_recursion=-1') def index_lt(a, x): 'return largest index s.t. A[i] < x or -1 if it does not exist' return bisect.bisect_left(a, x) - 1 def index_le(a, x): 'return largest index s.t. A[i] <= x or -1 if it does not exist' return bisect.bisect_right(a, x) - 1 def index_gt(a, x): 'return smallest index s.t. A[i] > x or len(a) if it does not exist' return bisect.bisect_right(a, x) def index_ge(a, x): 'return smallest index s.t. A[i] >= x or len(a) if it does not exist' return bisect.bisect_left(a, x) class CumulativeSum2D: def __init__(self, A): self.A = A self.H = len(A) self.W = len(A[0]) self.S = [[0 for _ in range(self.W + 1)] for _ in range(self.H + 1)] for i in range(self.H): for j in range(self.W): self.S[i + 1][j + 1] = self.S[i + 1][j] + self.S[i][j + 1] - self.S[i][j] + self.A[i][j] def sum(self, lx, ly, rx, ry): if lx > rx or ly > ry: return 0 return self.S[rx + 1][ry + 1] - self.S[lx][ry + 1] - self.S[rx + 1][ly] + self.S[lx][ly] H, W = map(int, input().split()) A = [list(map(int, input().split())) for _ in range(H)] mod = 10 ** 9 + 7 is_zero = [[1 if A[i][j] == 0 else 0 for j in range(W)] for i in range(H)] A = [[A[i][j] if A[i][j] > 0 else 1 for j in range(W)] for i in range(H)] R = [] for i in range(H): acc = 1 for j in range(W): acc *= A[i][j] acc %= mod R.append(acc) C = [] for j in range(W): acc = 1 for i in range(H): acc *= A[i][j] acc %= mod C.append(acc) S = 1 for i in range(H): S *= R[i] S %= mod CZ = CumulativeSum2D(is_zero) Q = int(input()) for _ in range(Q): r, c = map(lambda x: int(x) - 1, input().split()) zero = 0 zero += CZ.sum(0, 0, r - 1, c - 1) zero += CZ.sum(0, c + 1, r - 1, W - 1) zero += CZ.sum(r + 1, 0, H - 1, c - 1) zero += CZ.sum(r + 1, c + 1, H - 1, W - 1) if zero > 0: print(0) else: print(S * pow(R[r], mod - 2, mod) * pow(C[c], mod - 2, mod) * A[r][c] % mod)