結果
問題 | No.1141 田グリッド |
ユーザー | terasa |
提出日時 | 2022-05-30 20:35:44 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,228 bytes |
コンパイル時間 | 153 ms |
コンパイル使用メモリ | 82,552 KB |
実行使用メモリ | 93,824 KB |
最終ジャッジ日時 | 2024-09-21 00:54:09 |
合計ジャッジ時間 | 8,070 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
57,152 KB |
testcase_01 | AC | 48 ms
56,252 KB |
testcase_02 | AC | 44 ms
55,340 KB |
testcase_03 | AC | 45 ms
56,640 KB |
testcase_04 | AC | 44 ms
55,888 KB |
testcase_05 | AC | 43 ms
56,084 KB |
testcase_06 | AC | 43 ms
56,048 KB |
testcase_07 | AC | 42 ms
55,644 KB |
testcase_08 | AC | 68 ms
73,356 KB |
testcase_09 | AC | 64 ms
69,464 KB |
testcase_10 | AC | 68 ms
72,376 KB |
testcase_11 | AC | 65 ms
70,660 KB |
testcase_12 | AC | 75 ms
75,000 KB |
testcase_13 | AC | 272 ms
88,500 KB |
testcase_14 | AC | 389 ms
93,824 KB |
testcase_15 | AC | 277 ms
81,144 KB |
testcase_16 | AC | 276 ms
80,912 KB |
testcase_17 | AC | 286 ms
80,976 KB |
testcase_18 | AC | 278 ms
82,972 KB |
testcase_19 | AC | 275 ms
83,092 KB |
testcase_20 | AC | 276 ms
82,960 KB |
testcase_21 | AC | 269 ms
80,560 KB |
testcase_22 | AC | 270 ms
80,572 KB |
testcase_23 | AC | 271 ms
81,024 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
ソースコード
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 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 is_zero = [[1 if A[i][j] == 0 else 0 for j in range(W)] for _ in range(H)] 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)