結果
問題 | No.2612 Close the Distance |
ユーザー |
|
提出日時 | 2024-01-06 13:20:12 |
言語 | Nim (2.2.0) |
結果 |
AC
|
実行時間 | 1,213 ms / 3,000 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 3,612 ms |
コンパイル使用メモリ | 66,884 KB |
実行使用メモリ | 47,576 KB |
最終ジャッジ日時 | 2024-09-28 05:14:08 |
合計ジャッジ時間 | 23,241 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
import strutils, sequtilsiterator readInt(): int {.closure.} =while true:let line = stdin.readLine.split.map(parseInt)for x in line:yield xvar input = readIntlet n = input()varx = newSeq[int64]()y = newSeq[int64]()for _ in 0..<n:let (a, b) = (input(), input())x.add(a + b)y.add(b - a)let xy = zip(x, y)iterator exclude_box(xy: openArray[(int64, int64)], box_x, box_y, a: int64): (int64, int64) =for (x, y) in xy:if not (box_x <= x and x <= box_x + a and box_y <= y and y <= box_y + a):yield (x, y)proc is_not_more_than(xy: openArray[(int64, int64)], a, k: int64): bool =if xy.len <= k:return trueif k == 0:return falseletx_min = xy.mapIt(it[0]).minx_max = xy.mapIt(it[0]).maxy_min = xy.mapIt(it[1]).miny_max = xy.mapIt(it[1]).maxif is_not_more_than(exclude_box(xy, x_min, y_min, a).toSeq, a, k - 1):return trueif k >= 2 and is_not_more_than(exclude_box(xy, x_min, y_max - a, a).toSeq, a, k - 1):return trueif k >= 3 and is_not_more_than(exclude_box(xy, x_max - a, y_min, a).toSeq, a, k - 1):return trueif k >= 3 and is_not_more_than(exclude_box(xy, x_max - a, y_max - a, a).toSeq, a, k - 1):return truefalselet max_a = max(x.max - x.min, y.max - y.min)varng = -1i64ok = max_awhile ok - ng > 1:let m = (ok + ng) div 2if is_not_more_than(xy, m, 3):ok = melse:ng = mecho ok