結果
問題 | No.1151 チャレンジゲーム |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-08-08 00:45:58 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 43 ms / 2,000 ms |
コード長 | 3,684 bytes |
コンパイル時間 | 2,513 ms |
コンパイル使用メモリ | 161,104 KB |
実行使用メモリ | 12,712 KB |
最終ジャッジ日時 | 2023-09-04 08:56:32 |
合計ジャッジ時間 | 5,611 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,380 KB |
testcase_03 | AC | 1 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,380 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,380 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 2 ms
4,380 KB |
testcase_09 | AC | 1 ms
4,380 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 2 ms
4,380 KB |
testcase_12 | AC | 2 ms
4,376 KB |
testcase_13 | AC | 14 ms
5,056 KB |
testcase_14 | AC | 14 ms
4,468 KB |
testcase_15 | AC | 14 ms
5,616 KB |
testcase_16 | AC | 14 ms
5,012 KB |
testcase_17 | AC | 15 ms
6,064 KB |
testcase_18 | AC | 14 ms
6,324 KB |
testcase_19 | AC | 15 ms
5,024 KB |
testcase_20 | AC | 14 ms
5,060 KB |
testcase_21 | AC | 13 ms
6,064 KB |
testcase_22 | AC | 13 ms
4,496 KB |
testcase_23 | AC | 14 ms
5,512 KB |
testcase_24 | AC | 13 ms
6,040 KB |
testcase_25 | AC | 14 ms
4,616 KB |
testcase_26 | AC | 14 ms
5,032 KB |
testcase_27 | AC | 15 ms
5,064 KB |
testcase_28 | AC | 38 ms
7,880 KB |
testcase_29 | AC | 33 ms
8,360 KB |
testcase_30 | AC | 37 ms
7,912 KB |
testcase_31 | AC | 29 ms
8,656 KB |
testcase_32 | AC | 38 ms
7,364 KB |
testcase_33 | AC | 38 ms
7,888 KB |
testcase_34 | AC | 35 ms
8,836 KB |
testcase_35 | AC | 39 ms
11,732 KB |
testcase_36 | AC | 41 ms
11,236 KB |
testcase_37 | AC | 39 ms
8,876 KB |
testcase_38 | AC | 36 ms
6,652 KB |
testcase_39 | AC | 34 ms
8,148 KB |
testcase_40 | AC | 40 ms
7,388 KB |
testcase_41 | AC | 33 ms
12,480 KB |
testcase_42 | AC | 40 ms
12,712 KB |
testcase_43 | AC | 36 ms
7,548 KB |
testcase_44 | AC | 31 ms
6,616 KB |
testcase_45 | AC | 39 ms
8,332 KB |
testcase_46 | AC | 43 ms
9,176 KB |
testcase_47 | AC | 35 ms
8,408 KB |
testcase_48 | AC | 11 ms
4,380 KB |
testcase_49 | AC | 16 ms
12,064 KB |
testcase_50 | AC | 33 ms
5,332 KB |
testcase_51 | AC | 40 ms
7,572 KB |
testcase_52 | AC | 41 ms
7,892 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)); } enum NUM_ITERS = 300; void main() { try { for (; ; ) { const N = readInt(); auto A = new int[N]; foreach (i; 0 .. N) { A[i] = readInt(); } auto sums = new int[1 << N]; foreach (i; 0 .. N) { foreach (p; 0 .. 1 << i) { sums[p | 1 << i] = sums[p] + A[i]; } } const ASum = sums[(1 << N) - 1]; auto dp1 = new real[][](1 << N, ASum + 1); auto dp0 = new real[][](1 << N, ASum + 1); foreach (x; 0 .. ASum + 1) { dp1[0][x] = dp0[0][x] = (x > ASum - x) ? 1.0L : 0.0L; } foreach (p; 1 .. 1 << N) { auto app = new bool[ASum + 1]; const sup = ((1 << N) - 1) ^ p; for (int q = sup; ; --q &= sup) { app[sums[q]] = true; if (q == 0) { break; } } foreach (x; 0 .. ASum + 1) { if (app[x]) { dp1[p][x] = -real.infinity; foreach (i; 0 .. N) { if (p & 1 << i) { real mn = +real.infinity; foreach (j; 0 .. N) { if (p & 1 << j) { /* t = (1/A[i]) dp0[*][*] + (1 - 1/A[i]) ((1/A[j]) dp1[*][*] + (1 - 1/A[i]) t) */ const t = ((1.0L / A[i]) * dp0[p ^ 1 << i][x + A[i]] + (1.0L - 1.0L / A[i]) * (1.0L / A[j]) * dp1[p ^ 1 << j][x]) / (1.0L - (1.0L - 1.0L / A[i]) * (1.0L - 1.0L / A[j])); chmin(mn, t); } } chmax(dp1[p][x], mn); } } dp0[p][x] = +real.infinity; foreach (i; 0 .. N) { if (p & 1 << i) { real mx = -real.infinity; foreach (j; 0 .. N) { if (p & 1 << j) { /* t = (1/A[i]) dp1[*][*] + (1 - 1/A[i]) ((1/A[j]) dp0[*][*] + (1 - 1/A[i]) t) */ const t = ((1.0L / A[i]) * dp1[p ^ 1 << i][x] + (1.0L - 1.0L / A[i]) * (1.0L / A[j]) * dp0[p ^ 1 << j][x + A[j]]) / (1.0L - (1.0L - 1.0L / A[i]) * (1.0L - 1.0L / A[j])); chmax(mx, t); } } chmin(dp0[p][x], mx); } } } } } writefln("%.12f", dp1[(1 << N) - 1][0]); } } catch (EOFException e) { } }