結果

問題 No.165 四角で囲え!
ユーザー noko2250noko2250
提出日時 2015-03-16 00:06:19
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,577 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 86,712 KB
実行使用メモリ 85,304 KB
最終ジャッジ日時 2023-09-11 08:28:08
合計ジャッジ時間 11,529 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 615 ms
79,348 KB
testcase_01 RE -
testcase_02 AC 75 ms
71,060 KB
testcase_03 AC 78 ms
71,228 KB
testcase_04 RE -
testcase_05 AC 803 ms
79,820 KB
testcase_06 AC 338 ms
77,764 KB
testcase_07 AC 77 ms
71,148 KB
testcase_08 AC 75 ms
70,980 KB
testcase_09 RE -
testcase_10 AC 74 ms
71,148 KB
testcase_11 RE -
testcase_12 AC 263 ms
79,180 KB
testcase_13 AC 329 ms
78,732 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 1,801 ms
79,832 KB
testcase_19 AC 951 ms
79,904 KB
testcase_20 AC 797 ms
79,708 KB
testcase_21 AC 799 ms
79,420 KB
testcase_22 AC 824 ms
79,488 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, i, j, k, l)
            if p > B :
                while j <= l and p > B :
                    j += 1
                    if j <= l : p = get_sum(points, i, j, k, l)
            
            if j <= l and p <= B :
                ans = max(ans, get_sum(counts, i, j, k, l))
                

    

print(ans)
0