結果

問題 No.165 四角で囲え!
ユーザー convexineqconvexineq
提出日時 2020-12-18 12:52:10
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,141 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 82,064 KB
最終ジャッジ日時 2023-10-21 08:01:21
合計ジャッジ時間 13,611 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,256 ms
77,488 KB
testcase_01 AC 41 ms
53,520 KB
testcase_02 AC 39 ms
53,520 KB
testcase_03 AC 39 ms
53,520 KB
testcase_04 AC 40 ms
53,520 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n,b = map(int,input().split())
xyp = []
sx = set()
sy = set()
for _ in range(n):
    x,y,p = map(int,input().split())
    xyp.append((x,y,p))
    sx.add(x)
    sy.add(y)
*sx, = sorted(sx)
*sy, = sorted(sy)
zx = {si:i for i,si in enumerate(sx)}
zy = {si:i for i,si in enumerate(sy)}

lx = len(sx)
ly = len(sy)
cnt = [[0]*ly for _ in range(lx)]
pts = [[0]*ly for _ in range(lx)]
for x,y,p in xyp:
    cnt[zx[x]][zy[y]] += 1
    pts[zx[x]][zy[y]] += p

for i in range(lx):
    for j in range(1,ly):
        cnt[i][j] += cnt[i][j-1]
        pts[i][j] += pts[i][j-1]
for j in range(ly):
    for i in range(1,lx):
        cnt[i][j] += cnt[i-1][j]
        pts[i][j] += pts[i-1][j]

ans = 0
for x0 in range(lx):
    for y0 in range(ly):
        for x1 in range(x0,lx):
            y1 = ly-1
            while y0 <= y1 and (pts[x1][y1] - (pts[x0-1][y1] if x0 else 0) - (pts[x1][y0-1] if y0 else 0) + (pts[x0-1][y0-1] if x0 and y0 else 0)) > b:
                y1 -= 1
            if y0 > y1: break
            ans = max(ans, cnt[x1][y1] - (cnt[x0-1][y1] if x0 else 0) - (cnt[x1][y0-1] if y0 else 0) + (cnt[x0-1][y0-1] if x0 and y0 else 0))
print(ans)
0