結果

問題 No.755 Zero-Sum Rectangle
ユーザー lllllll88938494
提出日時 2022-09-25 19:46:11
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 868 bytes
コンパイル時間 268 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 76,756 KB
最終ジャッジ日時 2024-12-22 14:10:33
合計ジャッジ時間 16,574 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())

a=[[0]*(m+2)]
for i in  range(m):
    a.append([0]+list(map(int,input().split()))+[0])
a.append([0]*(m+2))

cnt=[[0]*(m+2) for i in range(m+2)]

for i in range(1,len(a)):
    for j in range(1,len(a[i])):
        a[i][j] += a[i-1][j] + a[i][j-1] - a[i-1][j-1]
    

for i in range(1,m+1):
    for j in range(1,m+1):
        for k in range(i,m+1):
            for l in range(j,m+1):
                if  a[k][l] - a[i-1][l] - a[k][j-1] + a[i-1][j-1] == 0:
                    cnt[i][j] += 1
                    cnt[i][l+1] -= 1
                    cnt[k+1][j] -= 1
                    cnt[k+1][l+1] += 1

for i in range(1,m+1):
    for j in range(1,m):
        cnt[i][j+1] += cnt[i][j]

for j in range(1,m+1):
    for i in range(1,m):
        cnt[i+1][j] += cnt[i][j]

for i in range(n):
    x,y=map(int,input().split())
    print(cnt[x][y])
0