結果

問題 No.2612 Close the Distance
ユーザー MitarushiMitarushi
提出日時 2023-06-16 17:26:57
言語 Nim
(2.0.2)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,435 bytes
コンパイル時間 1,105 ms
コンパイル使用メモリ 65,500 KB
最終ジャッジ日時 2024-04-27 04:50:05
合計ジャッジ時間 2,120 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
/home/judge/data/code/Main.nim(9, 39) Error: type mismatch: got 'seq[int]' for 'map(split(readLine(stdin), " ", -1), parseInt)' but expected 'tuple'

ソースコード

diff #

import strutils, sequtils

let n = stdin.readLine.parseInt
var 
    x = newSeq[int64]()
    y = newSeq[int64]()
for _ in 0..<n:
    var a, b: int64
    (a, b) = stdin.readLine.split(" ").map(parseInt)
    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 true
    if k == 0:
        return false

    let 
        x_min = xy.mapIt(it[0]).min
        x_max = xy.mapIt(it[0]).max
        y_min = xy.mapIt(it[1]).min
        y_max = xy.mapIt(it[1]).max

    if is_not_more_than(exclude_box(xy, x_min, y_min, a).toSeq, a, k - 1):
        return true
    if k >= 2 and is_not_more_than(exclude_box(xy, x_min, y_max - a, a).toSeq, a, k - 1):
        return true
    if k >= 3 and is_not_more_than(exclude_box(xy, x_max - a, y_min, a).toSeq, a, k - 1):
        return true
    if k >= 3 and is_not_more_than(exclude_box(xy, x_max - a, y_max - a, a).toSeq, a, k - 1):
        return true
    false

let max_a = max(x.max - x.min, y.max - y.min)
var 
    ng = -1i64
    ok = max_a
while ok - ng > 1:
    let m = (ok + ng) div 2
    if is_not_more_than(xy, m, 3):
        ok = m
    else:
        ng = m
echo ok
0