結果

問題 No.755 Zero-Sum Rectangle
ユーザー vwxyzvwxyz
提出日時 2022-07-01 01:20:27
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,697 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 151,140 KB
最終ジャッジ日時 2023-08-16 12:57:40
合計ジャッジ時間 22,549 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
151,140 KB
testcase_01 AC 1,582 ms
79,360 KB
testcase_02 AC 1,966 ms
79,616 KB
testcase_03 TLE -
testcase_04 AC 1,897 ms
80,184 KB
testcase_05 AC 1,942 ms
79,456 KB
testcase_06 AC 1,328 ms
80,132 KB
testcase_07 AC 1,308 ms
79,576 KB
testcase_08 AC 1,755 ms
80,880 KB
testcase_09 AC 1,804 ms
79,460 KB
testcase_10 TLE -
testcase_11 AC 72 ms
71,252 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

class Cumsum2:
    def __init__(self,lst):
        self.H=len(lst)
        self.W=len(lst[0]) if lst else 0
        self.cumsum2=[[0]*(self.W+1) for i in range(self.H+1)]
        for i in range(1,self.H+1):
            for j in range(1,self.W+1):
                self.cumsum2[i][j]=lst[i-1][j-1]
        for i in range(self.H+1):
            for j in range(1,self.W+1):
                self.cumsum2[i][j]+=self.cumsum2[i][j-1]
        for i in range(1,self.H+1):
            for j in range(self.W+1):
                self.cumsum2[i][j]+=self.cumsum2[i-1][j]

    def __getitem__(self,tpl):
        ab,cd=tpl
        def make_slice(ij,N):
            if type(ij)==int:
                i,j=ij,ij+1
            else:
                i,j=ij.start,ij.stop
                if i==None or i<-N:
                    i=0
                elif N<=i:
                    i=N
                elif i<0:
                    i+=N
                if j==None or N<=j:
                    j=N
                elif j<-N:
                    j=0
                elif j<0:
                    j+=N
            return i,j
        a,b=make_slice(ab,self.H)
        c,d=make_slice(cd,self.W)
        return self.cumsum2[b][d]+self.cumsum2[a][c]-self.cumsum2[a][d]-self.cumsum2[b][c]

N,M=map(int,readline().split())
A=Cumsum2([list(map(int,readline().split())) for i in range(M)])
for _ in range(N):
    x,y=map(int,readline().split())
    x-=1;y-=1
    ans=0
    for i0 in range(x+1):
        for i1 in range(x+1,M+1):
            for j0 in range(y+1):
                for j1 in range(y+1,M+1):
                    if A[i0:i1,j0:j1]==0:
                        ans+=1
    print(ans)
0