結果
問題 | No.2248 max(C)-min(C) |
ユーザー | 👑 hos.lyric |
提出日時 | 2023-03-17 21:47:36 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 256 ms / 3,000 ms |
コード長 | 2,264 bytes |
コンパイル時間 | 974 ms |
コンパイル使用メモリ | 135,780 KB |
実行使用メモリ | 21,884 KB |
最終ジャッジ日時 | 2024-06-22 17:40:06 |
合計ジャッジ時間 | 8,617 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 3 ms
6,944 KB |
testcase_08 | AC | 3 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 3 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 75 ms
21,184 KB |
testcase_19 | AC | 10 ms
5,376 KB |
testcase_20 | AC | 76 ms
19,648 KB |
testcase_21 | AC | 76 ms
20,952 KB |
testcase_22 | AC | 50 ms
14,964 KB |
testcase_23 | AC | 32 ms
9,520 KB |
testcase_24 | AC | 15 ms
5,376 KB |
testcase_25 | AC | 66 ms
19,492 KB |
testcase_26 | AC | 63 ms
20,328 KB |
testcase_27 | AC | 76 ms
18,992 KB |
testcase_28 | AC | 9 ms
5,376 KB |
testcase_29 | AC | 72 ms
19,660 KB |
testcase_30 | AC | 28 ms
9,300 KB |
testcase_31 | AC | 76 ms
19,648 KB |
testcase_32 | AC | 15 ms
5,484 KB |
testcase_33 | AC | 24 ms
8,364 KB |
testcase_34 | AC | 75 ms
19,696 KB |
testcase_35 | AC | 79 ms
19,660 KB |
testcase_36 | AC | 81 ms
21,760 KB |
testcase_37 | AC | 43 ms
12,044 KB |
testcase_38 | AC | 176 ms
21,696 KB |
testcase_39 | AC | 170 ms
21,688 KB |
testcase_40 | AC | 175 ms
21,624 KB |
testcase_41 | AC | 145 ms
20,492 KB |
testcase_42 | AC | 186 ms
21,736 KB |
testcase_43 | AC | 157 ms
20,960 KB |
testcase_44 | AC | 172 ms
19,632 KB |
testcase_45 | AC | 131 ms
18,376 KB |
testcase_46 | AC | 68 ms
9,668 KB |
testcase_47 | AC | 173 ms
21,604 KB |
testcase_48 | AC | 166 ms
21,284 KB |
testcase_49 | AC | 247 ms
21,884 KB |
testcase_50 | AC | 256 ms
19,812 KB |
testcase_51 | AC | 245 ms
19,800 KB |
testcase_52 | AC | 243 ms
19,828 KB |
testcase_53 | AC | 36 ms
5,408 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; } 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)); } void main() { try { for (; ; ) { const N = readInt; auto A = new long[N]; foreach (i; 0 .. N) A[i] = readLong; auto B = new long[N]; foreach (i; 0 .. N) B[i] = readLong; foreach (i; 0 .. N) { if (A[i] > B[i]) { swap(A[i], B[i]); } } alias Entry = Tuple!(long, "val", int, "i", int, "s"); BinaryHeap!(Array!Entry, "a.val > b.val") que; long mx = long.min; foreach (i; 0 .. N) { que.insert(Entry(A[i], i, 0)); chmax(mx, A[i]); } long ans = long.max; for (; ; ) { debug { writeln(que.front, " ", mx); } const mn = que.front.val; const i = que.front.i; const s = que.front.s; que.removeFront; chmin(ans, mx - mn); if (s == 0) { que.insert(Entry((A[i] + B[i]) / 2, i, 1)); chmax(mx, (A[i] + B[i]) / 2); } else if (s == 1) { que.insert(Entry(B[i], i, 2)); chmax(mx, B[i]); } else { break; } } writeln(ans); } } catch (EOFException e) { } }