結果

問題 No.165 四角で囲え!
ユーザー noko2250noko2250
提出日時 2015-03-15 23:38:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,366 bytes
コンパイル時間 295 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 88,068 KB
最終ジャッジ日時 2023-09-11 08:25:12
合計ジャッジ時間 12,953 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
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 #

#Created on 2015/03/15 ans
import bisect

[N, B] = map(int, input().split())
X = []
Y = []
P = []
for _ in range(N) :
    [x, y, p] = map(int, input().split())
    X.append(x)
    Y.append(y)
    P.append(p)
    
xs = sorted(set(X), key=X.index)
ys = sorted(set(Y), key=Y.index)

points = [[0]*(N+1) for _ in range(N+1)]
counts = [[0]*(N+1) for _ in range(N+1)]

for i in range(N) :
    x = bisect.bisect_left(xs, X[i])
    y = bisect.bisect_left(ys, Y[i])
    points[y][x] += P[i]
    counts[y][x] += 1
    
for i in range(N+1) :
    for j in range(N+1) :
        if i > 0 :
            points[i][j] += points[i-1][j]
            counts[i][j] += counts[i-1][j]
        if j > 0 :
            points[i][j] += points[i][j-1]
            counts[i][j] += counts[i][j-1]
        if i > 0 and j > 0 :
            points[i][j] -= points[i-1][j-1]
            counts[i][j] -= counts[i-1][j-1]
            
            
def get_sum(L, a, b, c, d) :
    ret = 0
    ret += L[c][d]
    if a > 0 : ret -= L[a-1][d]
    if b > 0 : ret -= L[c][b-1]
    if a > 0 and b > 0 : ret += L[a-1][b-1]
    return ret

ans = 0
#(i,j) (k, l)
for i in range(N+1) :
    for j in range(N+1) :
        for k in range(i+1, N+1) :
            for l in range(j+1, N+1) :
                if get_sum(points,i,j,k,l) <= B :
                    ans = max(ans, get_sum(counts,i,j,k,l))
    

print(ans)
0