結果

問題 No.755 Zero-Sum Rectangle
ユーザー maspymaspy
提出日時 2020-02-19 15:30:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,144 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 51,028 KB
最終ジャッジ日時 2024-04-16 21:28:38
合計ジャッジ時間 17,515 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 458 ms
51,028 KB
testcase_01 AC 934 ms
44,228 KB
testcase_02 AC 1,091 ms
44,352 KB
testcase_03 AC 1,080 ms
44,484 KB
testcase_04 AC 1,144 ms
44,356 KB
testcase_05 AC 1,119 ms
44,232 KB
testcase_06 AC 1,024 ms
44,492 KB
testcase_07 AC 939 ms
44,480 KB
testcase_08 AC 1,119 ms
44,104 KB
testcase_09 AC 1,027 ms
44,012 KB
testcase_10 AC 1,130 ms
44,484 KB
testcase_11 AC 457 ms
44,484 KB
evil_1 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import numpy as np
stdin = open(0)

# %%
data = np.fromstring(stdin.read(), np.int64, sep=' ')

# %%
N, M = data[:2]
A = data[2: 2 + M * M].reshape(M, M)
XY = data[-N - N:] - 1


# %%
def zerosum_1D(A, i):
    """count zerosum ranges including A[i]"""
    n = len(A)
    Acum = np.zeros(n + 1, np.int64)
    Acum[1:] = A.cumsum()
    R = Acum[i + 1:]
    L = Acum[: i + 1]
    L.sort()
    R.sort()
    cnt = np.searchsorted(L, R, 'right') - np.searchsorted(L, R, 'left')
    return cnt.sum()


# %%
Acum = A.cumsum(axis=0)


# %%
def solve(x, y):
    ret = 0
    for i in range(x + 1):
        for j in range(x, M):
            B = Acum[j] - Acum[i] + A[i]
            ret += zerosum_1D(B, y)
    return ret


# %%
for x, y in XY.reshape(-1, 2):
    print(solve(x, y))
0