結果
問題 | No.165 四角で囲え! |
ユーザー | しらっ亭 |
提出日時 | 2015-07-05 04:14:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,153 ms / 5,000 ms |
コード長 | 1,691 bytes |
コンパイル時間 | 1,046 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 80,128 KB |
最終ジャッジ日時 | 2024-12-26 03:34:30 |
合計ジャッジ時間 | 8,090 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 287 ms
77,824 KB |
testcase_01 | AC | 47 ms
51,840 KB |
testcase_02 | AC | 50 ms
51,840 KB |
testcase_03 | AC | 50 ms
52,096 KB |
testcase_04 | AC | 51 ms
52,480 KB |
testcase_05 | AC | 419 ms
78,720 KB |
testcase_06 | AC | 214 ms
76,544 KB |
testcase_07 | AC | 51 ms
52,352 KB |
testcase_08 | AC | 49 ms
52,480 KB |
testcase_09 | AC | 49 ms
51,712 KB |
testcase_10 | AC | 51 ms
52,224 KB |
testcase_11 | AC | 230 ms
77,312 KB |
testcase_12 | AC | 130 ms
73,088 KB |
testcase_13 | AC | 167 ms
76,288 KB |
testcase_14 | AC | 122 ms
73,728 KB |
testcase_15 | AC | 114 ms
68,736 KB |
testcase_16 | AC | 510 ms
79,104 KB |
testcase_17 | AC | 368 ms
79,488 KB |
testcase_18 | AC | 1,153 ms
80,128 KB |
testcase_19 | AC | 430 ms
79,488 KB |
testcase_20 | AC | 354 ms
74,112 KB |
testcase_21 | AC | 372 ms
79,360 KB |
testcase_22 | AC | 362 ms
74,240 KB |
ソースコード
def zip(X): l = list(set(X)) l.sort() ma = l[-1] d = {x: i + 1 for i, x in enumerate(l)} return [d[x] for x in X], d[ma] + 1 def solve(N, B, X, Y, P): X, ma_x = zip(X) Y, ma_y = zip(Y) M = [[0] * ma_x for i in range(ma_y)] for i in range(N): M[Y[i]][X[i]] = P[i] S = [[0] * ma_x for i in range(ma_y)] C = [[0] * ma_x for i in range(ma_y)] for y in range(1, ma_y): sy1 = S[y - 1] cy1 = C[y - 1] my = M[y] sy = S[y] cy = C[y] for x in range(1, ma_x): m = my[x] sy[x] = sy[x - 1] + sy1[x] - sy1[x - 1] + m if m: cy[x] = cy[x - 1] + cy1[x] - cy1[x - 1] + 1 else: cy[x] = cy[x - 1] + cy1[x] - cy1[x - 1] ma = 0 for y1 in range(0, ma_y): sy1 = S[y1] cy1 = C[y1] for y2 in range(y1 + 1, ma_y): sy2 = S[y2] cy2 = C[y2] x1 = 0 x2 = 1 while x2 < ma_x: s = sy2[x2] - sy2[x1] - sy1[x2] + sy1[x1] if s <= B: c = cy2[x2] - cy2[x1] - cy1[x2] + cy1[x1] ma = max(ma, c) x2 += 1 else: if x1 == x2: x2 += 1 else: x1 += 1 print(ma) def main(): N, B = list(map(int, input().split())) X = [0] * N Y = [0] * N P = [0] * N for i in range(N): x, y, p = list(map(int, input().split())) X[i] = x Y[i] = y P[i] = p solve(N, B, X, Y, P) if __name__ == '__main__': main()