結果

問題 No.165 四角で囲え!
ユーザー ckawatakckawatak
提出日時 2017-09-19 18:14:04
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,602 ms / 5,000 ms
コード長 1,732 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,020 KB
実行使用メモリ 78,424 KB
最終ジャッジ日時 2023-08-26 23:49:49
合計ジャッジ時間 14,952 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 443 ms
76,768 KB
testcase_01 AC 75 ms
71,116 KB
testcase_02 AC 75 ms
71,208 KB
testcase_03 AC 73 ms
71,340 KB
testcase_04 AC 75 ms
71,468 KB
testcase_05 AC 583 ms
77,264 KB
testcase_06 AC 284 ms
77,384 KB
testcase_07 AC 74 ms
71,444 KB
testcase_08 AC 74 ms
71,468 KB
testcase_09 AC 73 ms
71,264 KB
testcase_10 AC 71 ms
71,068 KB
testcase_11 AC 847 ms
78,352 KB
testcase_12 AC 877 ms
78,052 KB
testcase_13 AC 1,256 ms
77,456 KB
testcase_14 AC 1,308 ms
77,788 KB
testcase_15 AC 1,200 ms
78,424 KB
testcase_16 AC 922 ms
78,292 KB
testcase_17 AC 623 ms
78,260 KB
testcase_18 AC 1,602 ms
77,572 KB
testcase_19 AC 683 ms
77,496 KB
testcase_20 AC 600 ms
77,364 KB
testcase_21 AC 588 ms
76,828 KB
testcase_22 AC 588 ms
76,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def compression_mapping(xs):
    ys = []
    for i in range(len(xs)):
        ys.append(i)
    ys.sort(key=xs.__getitem__)
    m = {}
    for i in ys:
        if xs[i] not in m:
            index = len(m)
            m[xs[i]] = index
    return m
    
def compress(m, xs):
    ys = []
    for i in range(len(xs)):
        ys.append(m[xs[i]])
    return ys

N,B = list(map(int, input().split(' ')))

X = [0 for _ in range(N)]
Y = [0 for _ in range(N)]
P = [0 for _ in range(N)]

for i in range(N):
    X[i],Y[i],P[i] = list(map(int, input().split(' ')))
    
X = compress(compression_mapping(X), X)
Y = compress(compression_mapping(Y), Y)
    
index = []
for i in range(N):
    index.append(i)
index.sort(key=X.__getitem__)    
    
solution = 0
for top in range(N+1):
    for bottom in range(top):
        count = 0
        score = 0
        right_end = 0
        right_pointer = 0
        left_end = 0
        left_pointer = 0
        
        while right_end < N:
            right_end += 1
            while right_pointer < N and X[index[right_pointer]] < right_end:
                if bottom <= Y[index[right_pointer]] and Y[index[right_pointer]] < top:
                    count += 1
                    score += P[index[right_pointer]]
                right_pointer += 1
                    
            while B < score:
                left_end += 1
                while left_pointer < N and X[index[left_pointer]] < left_end:
                    if bottom <= Y[index[left_pointer]] and Y[index[left_pointer]] < top:
                        count -= 1
                        score -= P[index[left_pointer]]
                    left_pointer += 1

            solution = max(solution, count)
                
print(solution)
0