結果

問題 No.755 Zero-Sum Rectangle
ユーザー AEnAEn
提出日時 2022-08-30 16:59:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,249 bytes
コンパイル時間 151 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 65,792 KB
最終ジャッジ日時 2024-04-25 01:46:14
合計ジャッジ時間 1,366 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 52 ms
65,024 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
evil_1 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(M)]
    A = [[0]*M for _ in range(M)]
    ac = [[0]*(M+1) for _ in range(M+1)]
    z = 0
    for i in range(M):
        for j in range(M):
            ac[i][j] += A[i][j]
            ac[-1][-1] += A[i][j]
            ac[-1][j] -= A[i][j]
            ac[i][-1] -= A[i][j]
            if A[i][j] == 0:
                z += 1
    if z==M*M:
        for i in range(N):
            x, y = map(int, input().split())
            print(x*y*(M-x+1)*(M-y+1))
        exit()
    for i in range(M+1):
        for j in range(1, M+1):
            ac[i][j] += ac[i][j-1]
    for i in range(1, M+1):
        for j in range(M+1):
            ac[i][j] += ac[i-1][j]
    res = [[0]*(M+1) for _ in range(M+1)]
    for i in range(M):
        for j in range(M):
            num = A[i][j]
            for x in range(i, M):
                for y in range(j, M):
                    if i==0 and j==0 and ac[x][y]==0:
                        res[i][j] += 1
                        res[x+1][y+1] += 1
                        res[i][y+1] -= 1
                        res[x+1][j] -= 1
                    elif i==0 and ac[x][y]-ac[x][j-1]==0:
                        res[i][j] += 1
                        res[x+1][y+1] += 1
                        res[i][y+1] -= 1
                        res[x+1][j] -= 1
                    elif j==0 and ac[x][y]-ac[i-1][y]==0:
                        res[i][j] += 1
                        res[x+1][y+1] += 1
                        res[i][y+1] -= 1
                        res[x+1][j] -= 1
                    else:
                        if ac[x][y]-ac[i-1][y]-ac[x][j-1]+ac[i-1][j-1]==0:
                            res[i][j] += 1
                            res[x+1][y+1] += 1
                            res[i][y+1] -= 1
                            res[x+1][j] -= 1

    for i in range(M+1):
        for j in range(1, M+1):
            res[i][j] += res[i][j-1]
    for i in range(1, M+1):
        for j in range(M+1):
            res[i][j] += res[i-1][j]
    for i in range(N):
        x, y = map(int,input().split())
        print(res[x-1][y-1])
if __name__=='__main__':
    main()
0