結果

問題 No.1998 Manhattan Restaurant
ユーザー 👑 hos.lyrichos.lyric
提出日時 2022-07-01 21:46:46
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 2,614 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 107,312 KB
実行使用メモリ 19,824 KB
最終ジャッジ日時 2023-09-04 17:35:21
合計ジャッジ時間 6,696 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,380 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 184 ms
19,216 KB
testcase_16 AC 99 ms
14,056 KB
testcase_17 AC 142 ms
14,324 KB
testcase_18 AC 102 ms
14,620 KB
testcase_19 AC 118 ms
14,132 KB
testcase_20 AC 181 ms
14,796 KB
testcase_21 AC 190 ms
14,648 KB
testcase_22 AC 191 ms
14,644 KB
testcase_23 AC 202 ms
14,764 KB
testcase_24 AC 197 ms
14,648 KB
testcase_25 AC 14 ms
7,748 KB
testcase_26 AC 113 ms
14,604 KB
testcase_27 AC 73 ms
7,460 KB
testcase_28 AC 116 ms
14,452 KB
testcase_29 AC 72 ms
7,712 KB
testcase_30 AC 160 ms
19,824 KB
testcase_31 AC 155 ms
17,436 KB
testcase_32 AC 19 ms
7,752 KB
testcase_33 AC 97 ms
14,276 KB
testcase_34 AC 124 ms
14,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;
long[] X, Y;

bool check(long k) {
  auto as = new long[N];
  auto bs = new long[N];
  auto cs = new long[N];
  auto ds = new long[N];
  foreach (i; 0 .. N) {
    as[i] = X[i] + Y[i] - k;
    bs[i] = X[i] + Y[i] + k;
    cs[i] = X[i] - Y[i] - k;
    ds[i] = X[i] - Y[i] + k;
  }
  long maxA = long.min, minB = long.max;
  long maxC = long.min, minD = long.max;
  foreach (i; 0 .. N) {
    chmax(maxA, as[i]); chmin(minB, bs[i]);
    chmax(maxC, cs[i]); chmin(minD, ds[i]);
  }
  debug {
    writeln("check ", k);
    writeln("  as = ", as);
    writeln("  bs = ", bs);
    writeln("  cs = ", cs);
    writeln("  ds = ", ds);
  }
  
  bool sub(long p0, long q0, long p1, long q1) {
    foreach (i; 0 .. N) {
      if (as[i] <= p0 && p0 <= bs[i] && cs[i] <= q0 && q0 <= ds[i]) continue;
      if (as[i] <= p1 && p1 <= bs[i] && cs[i] <= q1 && q1 <= ds[i]) continue;
      return false;
    }
    return true;
  }
  if (sub(maxA, maxC, minB, minD)) return true;
  if (sub(maxA, minD, minB, maxC)) return true;
  return false;
}

void main() {
  try {
    for (; ; ) {
      N = readInt;
      X = new long[N];
      Y = new long[N];
      foreach (i; 0 .. N) {
        X[i] = readLong;
        Y[i] = readLong;
      }
      
      long lo = -1, hi = 4 * 10L^^9 + 10;
      for (; lo + 1 < hi; ) {
        const mid = (lo + hi) / 2;
        (check(mid) ? hi : lo) = mid;
      }
      writeln(hi);
    }
  } catch (EOFException e) {
  }
}
0