結果

問題 No.755 Zero-Sum Rectangle
ユーザー lloyzlloyz
提出日時 2023-05-13 01:11:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,920 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 77,996 KB
最終ジャッジ日時 2023-08-19 07:12:37
合計ジャッジ時間 13,092 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,092 KB
testcase_01 AC 1,465 ms
77,712 KB
testcase_02 AC 947 ms
77,908 KB
testcase_03 AC 907 ms
77,756 KB
testcase_04 AC 888 ms
77,996 KB
testcase_05 AC 1,920 ms
77,960 KB
testcase_06 AC 870 ms
77,792 KB
testcase_07 AC 860 ms
77,396 KB
testcase_08 AC 857 ms
77,588 KB
testcase_09 AC 862 ms
77,892 KB
testcase_10 AC 848 ms
77,416 KB
testcase_11 AC 78 ms
76,044 KB
evil_1 AC 1,008 ms
78,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

n, m = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(m)]

DP = [[0 for _ in range(m + 1)] for _ in range(m + 1)]
for i in range(1, m + 1):
    for j in range(m):
        DP[i][j + 1] = DP[i][j] + A[i - 1][j]
for j in range(1, m + 1):
    for i in range(m):
        DP[i + 1][j] += DP[i][j]
ANS = [[0 for _ in range(m + 1)] for _ in range(m + 1)]
for si in range(m):
    for sj in range(m):
        for gi in range(si + 1, m + 1):
            for gj in range(sj + 1, m + 1):
                if DP[gi][gj] - DP[si][gj] - DP[gi][sj] + DP[si][sj] == 0:
                    ANS[si][sj] += 1
                    ANS[gi][gj] += 1
                    ANS[si][gj] -= 1
                    ANS[gi][sj] -= 1
for i in range(m + 1):
    for j in range(m):
        ANS[i][j + 1] += ANS[i][j]
for j in range(m + 1):
    for i in range(m):
        ANS[i + 1][j] += ANS[i][j]
for _ in range(n):
    x, y = map(int, input().split())
    print(ANS[x - 1][y - 1])
0