結果

問題 No.1141 田グリッド
ユーザー H3PO4H3PO4
提出日時 2023-07-15 09:41:33
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 880 ms / 2,000 ms
コード長 920 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 65,456 KB
最終ジャッジ日時 2023-10-15 00:24:11
合計ジャッジ時間 21,336 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
29,728 KB
testcase_01 AC 133 ms
29,684 KB
testcase_02 AC 133 ms
29,680 KB
testcase_03 AC 133 ms
29,684 KB
testcase_04 AC 135 ms
29,620 KB
testcase_05 AC 135 ms
29,612 KB
testcase_06 AC 134 ms
29,640 KB
testcase_07 AC 134 ms
29,624 KB
testcase_08 AC 145 ms
31,184 KB
testcase_09 AC 141 ms
30,444 KB
testcase_10 AC 146 ms
31,080 KB
testcase_11 AC 151 ms
31,996 KB
testcase_12 AC 146 ms
31,096 KB
testcase_13 AC 658 ms
54,724 KB
testcase_14 AC 880 ms
65,456 KB
testcase_15 AC 762 ms
57,880 KB
testcase_16 AC 773 ms
57,800 KB
testcase_17 AC 762 ms
57,732 KB
testcase_18 AC 673 ms
45,288 KB
testcase_19 AC 686 ms
45,108 KB
testcase_20 AC 674 ms
45,216 KB
testcase_21 AC 767 ms
57,888 KB
testcase_22 AC 772 ms
57,960 KB
testcase_23 AC 765 ms
57,780 KB
testcase_24 AC 740 ms
54,588 KB
testcase_25 AC 720 ms
54,436 KB
testcase_26 AC 758 ms
54,756 KB
testcase_27 AC 751 ms
54,676 KB
testcase_28 AC 723 ms
54,504 KB
testcase_29 AC 717 ms
51,544 KB
testcase_30 AC 716 ms
48,528 KB
testcase_31 AC 671 ms
45,200 KB
testcase_32 AC 735 ms
53,880 KB
testcase_33 AC 735 ms
53,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np

MOD = 1000000007
mul = np.frompyfunc(lambda x, y: x * y % MOD, 2, 1)
int1 = lambda x: int(x) - 1

H, W = map(int, input().split())
A = np.array([tuple(map(int, input().split())) for _ in range(H)], dtype=object)

Au = mul.accumulate(A, axis=0)
Ad = np.flipud(mul.accumulate(np.flipud(A), axis=0))

Aul = mul.accumulate(Au, axis=1).tolist()
Aur = np.fliplr(mul.accumulate(np.fliplr(Au), axis=1)).tolist()
Adl = mul.accumulate(Ad, axis=1).tolist()
Adr = np.fliplr(mul.accumulate(np.fliplr(Ad), axis=1)).tolist()

Q = int(input())
for _ in range(Q):
    ans = 1
    r, c = map(int1, input().split())
    if 0 < r and 0 < c:
        ans = ans * Aul[r - 1][c - 1] % MOD
    if 0 < r and c < W - 1:
        ans = ans * Aur[r - 1][c + 1] % MOD
    if r < H - 1 and 0 < c:
        ans = ans * Adl[r + 1][c - 1] % MOD
    if r < H - 1 and c < W - 1:
        ans = ans * Adr[r + 1][c + 1] % MOD
    print(ans)
0