結果

問題 No.165 四角で囲え!
ユーザー ckawatakckawatak
提出日時 2017-09-19 17:57:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,711 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 17,696 KB
最終ジャッジ日時 2024-04-25 18:12:43
合計ジャッジ時間 12,491 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

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)
    
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