結果
問題 | No.1361 [Zelkova 4th Tune *] QUADRUPLE-SEQUENCEの詩 |
ユーザー | 👑 hos.lyric |
提出日時 | 2021-01-22 21:53:43 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 543 ms / 2,000 ms |
コード長 | 4,070 bytes |
コンパイル時間 | 3,267 ms |
コンパイル使用メモリ | 166,440 KB |
実行使用メモリ | 23,112 KB |
最終ジャッジ日時 | 2023-09-04 11:57:27 |
合計ジャッジ時間 | 23,947 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,380 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 3 ms
4,380 KB |
testcase_09 | AC | 2 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,376 KB |
testcase_15 | AC | 4 ms
4,384 KB |
testcase_16 | AC | 3 ms
4,380 KB |
testcase_17 | AC | 3 ms
4,376 KB |
testcase_18 | AC | 25 ms
4,376 KB |
testcase_19 | AC | 11 ms
4,380 KB |
testcase_20 | AC | 26 ms
4,376 KB |
testcase_21 | AC | 11 ms
4,380 KB |
testcase_22 | AC | 17 ms
4,376 KB |
testcase_23 | AC | 25 ms
4,384 KB |
testcase_24 | AC | 25 ms
4,380 KB |
testcase_25 | AC | 26 ms
4,380 KB |
testcase_26 | AC | 28 ms
4,380 KB |
testcase_27 | AC | 16 ms
4,380 KB |
testcase_28 | AC | 203 ms
9,764 KB |
testcase_29 | AC | 174 ms
9,540 KB |
testcase_30 | AC | 153 ms
6,592 KB |
testcase_31 | AC | 183 ms
8,932 KB |
testcase_32 | AC | 261 ms
12,860 KB |
testcase_33 | AC | 142 ms
6,852 KB |
testcase_34 | AC | 228 ms
9,992 KB |
testcase_35 | AC | 251 ms
10,252 KB |
testcase_36 | AC | 401 ms
21,600 KB |
testcase_37 | AC | 97 ms
5,840 KB |
testcase_38 | AC | 187 ms
8,028 KB |
testcase_39 | AC | 120 ms
5,600 KB |
testcase_40 | AC | 152 ms
8,800 KB |
testcase_41 | AC | 233 ms
11,324 KB |
testcase_42 | AC | 360 ms
15,660 KB |
testcase_43 | AC | 222 ms
9,456 KB |
testcase_44 | AC | 265 ms
9,792 KB |
testcase_45 | AC | 206 ms
9,760 KB |
testcase_46 | AC | 244 ms
11,988 KB |
testcase_47 | AC | 145 ms
6,148 KB |
testcase_48 | AC | 389 ms
21,912 KB |
testcase_49 | AC | 339 ms
21,292 KB |
testcase_50 | AC | 417 ms
22,060 KB |
testcase_51 | AC | 393 ms
21,640 KB |
testcase_52 | AC | 312 ms
21,976 KB |
testcase_53 | AC | 543 ms
22,860 KB |
testcase_54 | AC | 530 ms
21,292 KB |
testcase_55 | AC | 541 ms
22,256 KB |
testcase_56 | AC | 535 ms
22,220 KB |
testcase_57 | AC | 340 ms
21,340 KB |
testcase_58 | AC | 259 ms
21,588 KB |
testcase_59 | AC | 259 ms
22,620 KB |
testcase_60 | AC | 276 ms
22,040 KB |
testcase_61 | AC | 274 ms
22,364 KB |
testcase_62 | AC | 274 ms
21,592 KB |
testcase_63 | AC | 91 ms
21,628 KB |
testcase_64 | AC | 92 ms
21,596 KB |
testcase_65 | AC | 89 ms
22,296 KB |
testcase_66 | AC | 91 ms
21,628 KB |
testcase_67 | AC | 91 ms
23,112 KB |
testcase_68 | AC | 2 ms
4,376 KB |
testcase_69 | AC | 2 ms
4,376 KB |
testcase_70 | AC | 1 ms
4,384 KB |
testcase_71 | AC | 2 ms
4,380 KB |
testcase_72 | AC | 2 ms
4,380 KB |
testcase_73 | AC | 1 ms
4,376 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)); } void main() { try { for (; ; ) { auto N = new int[4]; foreach (h; 0 .. 4) { N[h] = readInt(); } const S = readLong(); auto A = new long[][4]; foreach (h; 0 .. 4) { A[h] = new long[N[h]]; foreach (i; 0 .. N[h]) { A[h][i] = readLong(); } } alias Entry = Tuple!(long, "val", int, "i", int, "j"); Entry[] fs, gs; foreach (i; 0 .. N[0]) foreach (j; 0 .. N[1]) { fs ~= Entry(A[0][i] * A[1][j], i, j); } foreach (i; 0 .. N[2]) foreach (j; 0 .. N[3]) { gs ~= Entry(A[2][i] * A[3][j], i, j); } fs.sort; gs.sort; const fsLen = cast(int)(fs.length); const gsLen = cast(int)(gs.length); const int lbF = fs.lowerBound(Entry(0, int.min, int.min)); const int ubF = fs.upperBound(Entry(0, int.max, int.max)); const int lbG = gs.lowerBound(Entry(0, int.min, int.min)); const int ubG = gs.upperBound(Entry(0, int.max, int.max)); // <= t long calc(long t) { long ret; if (0 <= t) { ret += 1L * (ubF - lbF) * (gsLen - 0); ret += 1L * (fsLen - 0) * (ubG - lbG); ret -= 1L * (ubF - lbF) * (ubG - lbG); ret += 1L * (lbF - 0) * (gsLen - ubG); ret += 1L * (fsLen - ubF) * (lbG - 0); for (int i = lbF, j = 0; j < lbG; ++j) { for (; i > 0 && fs[i - 1].val * gs[j].val <= t; --i) {} ret += (lbF - i); } for (int i = ubF, j = gsLen; --j >= ubG; ) { for (; i < fsLen && fs[i].val * gs[j].val <= t; ++i) {} ret += (i - ubF); } } else { for (int i = 0, j = ubG; j < gsLen; ++j) { for (; i < lbF && fs[i].val * gs[j].val <= t; ++i) {} ret += (i - 0); } for (int i = fsLen, j = lbG; --j >= 0; ) { for (; i > ubF && fs[i - 1].val * gs[j].val <= t; --i) {} ret += (fsLen - i); } } return ret; } long lo = -10L^^18, hi = +10L^^18; for (; lo + 1 < hi; ) { const mid = (lo + hi) / 2; ((calc(mid) >= S) ? hi : lo) = mid; } writeln(hi); if (hi == 0) { writefln("%s %s %s %s", A[0][fs[lbF].i], A[1][fs[lbF].j], A[2][gs[lbG].i], A[3][gs[lbG].j]); } else { foreach (ref g; gs) { if (g.val != 0 && hi % g.val == 0) { const tar = hi / g.val; const pos = fs.lowerBound(Entry(tar, int.min, int.min)); if (pos < fsLen && fs[pos].val == tar) { writefln("%s %s %s %s", A[0][fs[pos].i], A[1][fs[pos].j], A[2][g.i], A[3][g.j]); break; } } } } } } catch (EOFException e) { } }