結果

問題 No.755 Zero-Sum Rectangle
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-25 19:36:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,060 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2023-08-24 01:47:29
合計ジャッジ時間 19,283 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 66 ms
71,412 KB
testcase_01 TLE -
testcase_02 AC 1,564 ms
77,792 KB
testcase_03 AC 1,506 ms
77,708 KB
testcase_04 AC 1,473 ms
77,996 KB
testcase_05 AC 1,459 ms
77,696 KB
testcase_06 AC 1,477 ms
78,080 KB
testcase_07 AC 1,478 ms
77,916 KB
testcase_08 AC 1,451 ms
77,316 KB
testcase_09 AC 1,446 ms
77,220 KB
testcase_10 AC 1,429 ms
77,244 KB
testcase_11 AC 76 ms
76,016 KB
evil_1 AC 1,571 ms
79,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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]
    
def  cal(right,left):
    rx,ry=right
    lx,ly=left
    return a[lx][ly] - a[rx-1][ly] - a[lx][ry-1] + a[rx-1][ry-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 cal((i,j),(k,l)) == 0:
                    cnt[i][j] += 1
                    if l+1 <= m:
                        cnt[i][l+1] -= 1
                    if k+1 <= m:
                        cnt[k+1][j] -= 1
                    if k+1 <= m and l+1 <= m:
                        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