結果

問題 No.755 Zero-Sum Rectangle
ユーザー htkbhtkb
提出日時 2018-12-14 13:01:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 863 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 11,820 KB
実行使用メモリ 27,048 KB
最終ジャッジ日時 2023-10-25 09:57:25
合計ジャッジ時間 3,774 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,220 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 #

import sys
from itertools import accumulate, product

N, M = map(int, input().split())
a = [[0]*(M+1)]
for _ in [0]*M:
    a.append([0]+[a[-1][i]+n for i, n in enumerate(accumulate(map(int, input().split())), start=1)])

result = [[0]*(M+2) for _ in [0]*(M+2)]
for from_x, from_y in product(range(1, M+1), repeat=2):
    for to_x, to_y in product(range(from_x, M+1), range(from_y, M+1)):
        if a[to_y][to_x] - a[from_y-1][to_x] - a[to_y][from_x-1] + a[from_y-1][from_x-1] == 0:
            result[from_y][from_x] += 1
            result[from_y][to_x+1] -= 1
            result[to_y+1][from_x] -= 1
            result[to_y+1][to_x+1] += 1

for y, row in enumerate(result[1:], start=1):
    for x, v in enumerate(accumulate(row)):
        result[y][x] = v + result[y-1][x]

print(*[result[x][y] for l in sys.stdin for x, y in (map(int, l.split()),)], sep="\n")
0