結果

問題 No.755 Zero-Sum Rectangle
コンテスト
ユーザー htkb
提出日時 2018-12-14 13:03:28
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
TLE  
実行時間 -
コード長 863 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 153 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 82,304 KB
最終ジャッジ日時 2026-04-12 09:22:09
合計ジャッジ時間 22,375 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 TLE * 3
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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