結果

問題 No.165 四角で囲え!
ユーザー maspymaspy
提出日時 2020-03-21 15:26:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,752 ms / 5,000 ms
コード長 933 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 86,852 KB
実行使用メモリ 78,068 KB
最終ジャッジ日時 2023-08-24 15:20:27
合計ジャッジ時間 30,363 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,467 ms
77,192 KB
testcase_01 AC 72 ms
71,188 KB
testcase_02 AC 72 ms
71,260 KB
testcase_03 AC 72 ms
70,880 KB
testcase_04 AC 73 ms
71,248 KB
testcase_05 AC 1,831 ms
77,468 KB
testcase_06 AC 452 ms
77,072 KB
testcase_07 AC 76 ms
71,176 KB
testcase_08 AC 73 ms
71,112 KB
testcase_09 AC 72 ms
71,340 KB
testcase_10 AC 73 ms
71,348 KB
testcase_11 AC 1,052 ms
77,348 KB
testcase_12 AC 638 ms
76,972 KB
testcase_13 AC 630 ms
76,872 KB
testcase_14 AC 481 ms
76,768 KB
testcase_15 AC 552 ms
76,772 KB
testcase_16 AC 2,660 ms
77,448 KB
testcase_17 AC 2,691 ms
77,716 KB
testcase_18 AC 2,752 ms
78,068 KB
testcase_19 AC 2,728 ms
77,632 KB
testcase_20 AC 2,715 ms
77,564 KB
testcase_21 AC 2,733 ms
77,552 KB
testcase_22 AC 2,726 ms
77,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

N, B = map(int, readline().split())
m = map(int, read().split())
X, Y, P = zip(*zip(m, m, m))


def compress(A):
    x_to_i = {x: i for i, x in enumerate(sorted(set(A)))}
    return tuple(x_to_i[x] for x in A)


X = compress(X)
Y = compress(Y)
H = max(X)
W = max(Y)
best_N = 0
for i, j in itertools.combinations(range(W + 2), 2):
    Ns = [0] * (H + 2)
    Ps = [0] * (H + 2)
    INF = B + 10
    Ps[-1] = INF
    for x, y, p in zip(X, Y, P):
        if i <= y < j:
            Ns[x] += 1
            Ps[x] += p
    R = 0
    S = 0
    N = 0
    for L in range(H + 1):
        while R < L or S + Ps[R] <= B:
            N += Ns[R]
            S += Ps[R]
            R += 1
        if best_N < N:
            best_N = N
        S -= Ps[L]
        N -= Ns[L]

print(best_N)
0