結果

問題 No.755 Zero-Sum Rectangle
ユーザー SalmonizeSalmonize
提出日時 2020-04-01 23:42:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 794 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 82,068 KB
最終ジャッジ日時 2023-09-09 20:20:22
合計ジャッジ時間 3,838 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,236 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
evil_1 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import combinations

n, m = map(int, input().split())
l = [[0]*(m+1)] + [[0] + list(map(int, input().split())) for _ in range(m)]
g = [[0]*(m+1) for _ in range(m+1)]
for i in range(m):
    for j in range(m):
        l[i+1][j+1] += l[i+1][j]
for i in range(m):
    for j in range(m):
        l[i+1][j+1] += l[i][j+1]
for i,a in combinations(range(m+1), 2):
    for j,b in combinations(range(m+1), 2):
        if l[a][b] - l[i][b] - l[a][j] + l[i][j] == 0:
            g[i][j] += 1
            g[a][b] += 1
            g[i][b] -= 1
            g[a][j] -= 1
for i in range(m+1):
    for j in range(m):
        g[i][j+1] += g[i][j]
for j in range(m+1):
    for i in range(m):
        g[i+1][j] += g[i][j]
for _ in range(n):
    x, y = map(int, input().split())
    print(g[x-1][y-1])
0