結果
問題 | No.1151 チャレンジゲーム |
ユーザー | 👑 hos.lyric |
提出日時 | 2020-08-07 21:36:36 |
言語 | D (dmd 2.107.1) |
結果 |
AC
|
実行時間 | 1,100 ms / 2,000 ms |
コード長 | 2,801 bytes |
コンパイル時間 | 2,802 ms |
コンパイル使用メモリ | 160,976 KB |
実行使用メモリ | 12,852 KB |
最終ジャッジ日時 | 2023-09-04 08:50:46 |
合計ジャッジ時間 | 33,130 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 5 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | AC | 3 ms
4,376 KB |
testcase_11 | AC | 5 ms
4,376 KB |
testcase_12 | AC | 5 ms
4,376 KB |
testcase_13 | AC | 364 ms
6,316 KB |
testcase_14 | AC | 354 ms
4,596 KB |
testcase_15 | AC | 338 ms
5,024 KB |
testcase_16 | AC | 358 ms
5,012 KB |
testcase_17 | AC | 378 ms
6,352 KB |
testcase_18 | AC | 373 ms
5,012 KB |
testcase_19 | AC | 368 ms
5,012 KB |
testcase_20 | AC | 332 ms
5,064 KB |
testcase_21 | AC | 316 ms
6,336 KB |
testcase_22 | AC | 331 ms
4,548 KB |
testcase_23 | AC | 328 ms
6,720 KB |
testcase_24 | AC | 332 ms
5,016 KB |
testcase_25 | AC | 322 ms
6,600 KB |
testcase_26 | AC | 345 ms
5,136 KB |
testcase_27 | AC | 381 ms
5,068 KB |
testcase_28 | AC | 943 ms
7,388 KB |
testcase_29 | AC | 876 ms
8,120 KB |
testcase_30 | AC | 938 ms
7,908 KB |
testcase_31 | AC | 774 ms
8,388 KB |
testcase_32 | AC | 954 ms
7,912 KB |
testcase_33 | AC | 967 ms
9,160 KB |
testcase_34 | AC | 913 ms
7,380 KB |
testcase_35 | AC | 990 ms
11,768 KB |
testcase_36 | AC | 1,019 ms
12,788 KB |
testcase_37 | AC | 1,020 ms
7,896 KB |
testcase_38 | AC | 897 ms
6,832 KB |
testcase_39 | AC | 861 ms
7,972 KB |
testcase_40 | AC | 1,032 ms
7,640 KB |
testcase_41 | AC | 780 ms
11,988 KB |
testcase_42 | AC | 1,005 ms
11,724 KB |
testcase_43 | AC | 911 ms
8,880 KB |
testcase_44 | AC | 770 ms
7,452 KB |
testcase_45 | AC | 1,056 ms
8,912 KB |
testcase_46 | AC | 1,100 ms
9,168 KB |
testcase_47 | AC | 954 ms
7,984 KB |
testcase_48 | AC | 208 ms
4,376 KB |
testcase_49 | AC | 217 ms
12,852 KB |
testcase_50 | AC | 781 ms
5,444 KB |
testcase_51 | AC | 1,039 ms
7,908 KB |
testcase_52 | AC | 1,070 ms
7,964 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]) { real f1 = 1.0L, f0 = 0.0L; foreach (iter; 0 .. NUM_ITERS) { f1 = 0.0L; foreach (i; 0 .. N) { if (p & 1 << i) { chmax(f1, (1.0L / A[i]) * dp0[p ^ 1 << i][x + A[i]] + (1.0L - 1.0L / A[i]) * f0); } } f0 = 1.0L; foreach (i; 0 .. N) { if (p & 1 << i) { chmin(f0, (1.0L / A[i]) * dp1[p ^ 1 << i][x] + (1.0L - 1.0L / A[i]) * f1); } } } dp1[p][x] = f1; dp0[p][x] = f0; } } } writefln("%.12f", dp1[(1 << N) - 1][0]); } } catch (EOFException e) { } }