結果

問題 No.165 四角で囲え!
ユーザー noko2250noko2250
提出日時 2015-03-16 00:16:57
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,091 ms / 5,000 ms
コード長 1,577 bytes
コンパイル時間 1,237 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 80,740 KB
最終ジャッジ日時 2023-08-26 23:38:55
合計ジャッジ時間 15,108 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 693 ms
79,484 KB
testcase_01 AC 73 ms
71,484 KB
testcase_02 AC 74 ms
71,184 KB
testcase_03 AC 74 ms
71,352 KB
testcase_04 AC 75 ms
71,272 KB
testcase_05 AC 1,030 ms
80,000 KB
testcase_06 AC 360 ms
78,320 KB
testcase_07 AC 75 ms
71,056 KB
testcase_08 AC 72 ms
71,456 KB
testcase_09 AC 74 ms
71,464 KB
testcase_10 AC 74 ms
71,020 KB
testcase_11 AC 502 ms
79,340 KB
testcase_12 AC 282 ms
78,976 KB
testcase_13 AC 320 ms
78,540 KB
testcase_14 AC 232 ms
77,964 KB
testcase_15 AC 223 ms
78,544 KB
testcase_16 AC 1,357 ms
80,472 KB
testcase_17 AC 1,075 ms
80,600 KB
testcase_18 AC 2,091 ms
80,740 KB
testcase_19 AC 1,234 ms
80,156 KB
testcase_20 AC 1,028 ms
79,852 KB
testcase_21 AC 1,009 ms
79,800 KB
testcase_22 AC 1,024 ms
79,684 KB
権限があれば一括ダウンロードができます

ソースコード

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(list(set(X)))
ys = sorted(list(set(Y)))

points = [[0]*len(xs) for _ in range(len(ys))]
counts = [[0]*len(xs) for _ in range(len(ys))]

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(len(ys)) :
    for j in range(len(xs)) :
        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(len(xs)) :
    for k in range(i, len(xs)) :
        j = 0
        for l in range(len(ys)) :
            p = get_sum(points, j, i, l, k)
            if p > B :
                while j <= l and p > B :
                    j += 1
                    if j <= l : p = get_sum(points, j, i, l, k)
            
            if j <= l and p <= B :
                ans = max(ans, get_sum(counts, j, i, l, k))
                

    

print(ans)
0