結果

問題 No.165 四角で囲え!
ユーザー convexineqconvexineq
提出日時 2020-12-18 15:12:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,962 ms / 5,000 ms
コード長 1,250 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 79,180 KB
最終ジャッジ日時 2023-10-21 08:08:20
合計ジャッジ時間 15,994 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 758 ms
77,528 KB
testcase_01 AC 39 ms
53,448 KB
testcase_02 AC 40 ms
53,448 KB
testcase_03 AC 39 ms
53,448 KB
testcase_04 AC 41 ms
53,448 KB
testcase_05 AC 985 ms
78,484 KB
testcase_06 AC 268 ms
77,556 KB
testcase_07 AC 40 ms
53,448 KB
testcase_08 AC 39 ms
53,448 KB
testcase_09 AC 40 ms
53,448 KB
testcase_10 AC 39 ms
53,448 KB
testcase_11 AC 500 ms
77,084 KB
testcase_12 AC 263 ms
76,708 KB
testcase_13 AC 350 ms
77,092 KB
testcase_14 AC 213 ms
76,300 KB
testcase_15 AC 214 ms
76,360 KB
testcase_16 AC 1,367 ms
79,068 KB
testcase_17 AC 1,196 ms
78,516 KB
testcase_18 AC 1,962 ms
78,972 KB
testcase_19 AC 1,323 ms
79,180 KB
testcase_20 AC 1,202 ms
78,516 KB
testcase_21 AC 1,205 ms
78,528 KB
testcase_22 AC 1,207 ms
78,524 KB
権限があれば一括ダウンロードができます

ソースコード

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]

def get_sum(a,h1,h2,w1,w2): #閉長方形 [h1からh2]*[w1からw2] の和
    if h1 and w1: return a[h2][w2] - a[h1-1][w2] - a[h2][w1-1] + a[h1-1][w1-1]
    elif h1: return a[h2][w2] - a[h1-1][w2]
    elif w1: return a[h2][w2] - a[h2][w1-1]
    else: return a[h2][w2]

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