結果
問題 | No.1998 Manhattan Restaurant |
ユーザー | 👑 hos.lyric |
提出日時 | 2022-07-01 21:46:46 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 173 ms / 2,000 ms |
コード長 | 2,614 bytes |
コンパイル時間 | 863 ms |
コンパイル使用メモリ | 120,552 KB |
実行使用メモリ | 20,708 KB |
最終ジャッジ日時 | 2024-06-22 15:35:01 |
合計ジャッジ時間 | 4,853 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 1 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 3 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,940 KB |
testcase_15 | AC | 146 ms
14,376 KB |
testcase_16 | AC | 80 ms
13,856 KB |
testcase_17 | AC | 114 ms
13,848 KB |
testcase_18 | AC | 87 ms
14,268 KB |
testcase_19 | AC | 100 ms
16,576 KB |
testcase_20 | AC | 155 ms
14,332 KB |
testcase_21 | AC | 167 ms
20,688 KB |
testcase_22 | AC | 163 ms
20,672 KB |
testcase_23 | AC | 173 ms
20,708 KB |
testcase_24 | AC | 168 ms
20,692 KB |
testcase_25 | AC | 12 ms
7,396 KB |
testcase_26 | AC | 96 ms
17,528 KB |
testcase_27 | AC | 61 ms
7,252 KB |
testcase_28 | AC | 90 ms
13,848 KB |
testcase_29 | AC | 60 ms
7,396 KB |
testcase_30 | AC | 127 ms
13,992 KB |
testcase_31 | AC | 123 ms
14,408 KB |
testcase_32 | AC | 16 ms
7,404 KB |
testcase_33 | AC | 79 ms
13,692 KB |
testcase_34 | AC | 100 ms
14,324 KB |
ソースコード
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) { } }