結果

問題 No.165 四角で囲え!
ユーザー しらっ亭しらっ亭
提出日時 2015-07-05 04:14:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,007 ms / 5,000 ms
コード長 1,691 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 81,012 KB
最終ジャッジ日時 2023-08-26 23:45:38
合計ジャッジ時間 7,084 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
79,316 KB
testcase_01 AC 73 ms
71,468 KB
testcase_02 AC 74 ms
71,152 KB
testcase_03 AC 74 ms
71,628 KB
testcase_04 AC 75 ms
71,140 KB
testcase_05 AC 379 ms
79,588 KB
testcase_06 AC 200 ms
77,896 KB
testcase_07 AC 73 ms
71,256 KB
testcase_08 AC 73 ms
71,384 KB
testcase_09 AC 73 ms
71,468 KB
testcase_10 AC 72 ms
71,244 KB
testcase_11 AC 214 ms
78,628 KB
testcase_12 AC 132 ms
77,904 KB
testcase_13 AC 159 ms
77,796 KB
testcase_14 AC 123 ms
77,168 KB
testcase_15 AC 118 ms
76,096 KB
testcase_16 AC 455 ms
80,732 KB
testcase_17 AC 324 ms
80,552 KB
testcase_18 AC 1,007 ms
81,012 KB
testcase_19 AC 382 ms
80,904 KB
testcase_20 AC 332 ms
80,752 KB
testcase_21 AC 328 ms
80,684 KB
testcase_22 AC 325 ms
80,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def zip(X):
    l = list(set(X))
    l.sort()
    ma = l[-1]
    d = {x: i + 1 for i, x in enumerate(l)}
    return [d[x] for x in X], d[ma] + 1


def solve(N, B, X, Y, P):
    X, ma_x = zip(X)
    Y, ma_y = zip(Y)

    M = [[0] * ma_x for i in range(ma_y)]

    for i in range(N):
        M[Y[i]][X[i]] = P[i]

    S = [[0] * ma_x for i in range(ma_y)]
    C = [[0] * ma_x for i in range(ma_y)]

    for y in range(1, ma_y):
        sy1 = S[y - 1]
        cy1 = C[y - 1]
        my = M[y]
        sy = S[y]
        cy = C[y]

        for x in range(1, ma_x):
            m = my[x]
            sy[x] = sy[x - 1] + sy1[x] - sy1[x - 1] + m
            if m:
                cy[x] = cy[x - 1] + cy1[x] - cy1[x - 1] + 1
            else:
                cy[x] = cy[x - 1] + cy1[x] - cy1[x - 1]

    ma = 0
    for y1 in range(0, ma_y):
        sy1 = S[y1]
        cy1 = C[y1]
        for y2 in range(y1 + 1, ma_y):
            sy2 = S[y2]
            cy2 = C[y2]
            x1 = 0
            x2 = 1
            while x2 < ma_x:
                s = sy2[x2] - sy2[x1] - sy1[x2] + sy1[x1]
                if s <= B:
                    c = cy2[x2] - cy2[x1] - cy1[x2] + cy1[x1]
                    ma = max(ma, c)
                    x2 += 1
                else:
                    if x1 == x2:
                        x2 += 1
                    else:
                        x1 += 1

    print(ma)


def main():
    N, B = list(map(int, input().split()))
    X = [0] * N
    Y = [0] * N
    P = [0] * N
    for i in range(N):
        x, y, p = list(map(int, input().split()))
        X[i] = x
        Y[i] = y
        P[i] = p
    solve(N, B, X, Y, P)


if __name__ == '__main__':
    main()
0