結果
| 問題 |
No.174 カードゲーム(Hard)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-10 03:41:04 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 386 ms / 2,000 ms |
| コード長 | 2,810 bytes |
| コンパイル時間 | 2,783 ms |
| コンパイル使用メモリ | 164,352 KB |
| 実行使用メモリ | 35,456 KB |
| 最終ジャッジ日時 | 2024-06-13 02:29:14 |
| 合計ジャッジ時間 | 6,464 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 |
ソースコード
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, 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[0]; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }
void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }
int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }
int N;
real[] P;
int[][] A;
void main() {
try {
for (; ; ) {
N = readInt();
P = new real[2];
foreach (h; 0 .. 2) {
P[h] = readReal();
}
A = new int[][](2, N);
foreach (h; 0 .. 2) {
foreach (i; 0 .. N) {
A[h][i] = readInt();
}
A[h].sort;
}
auto prob = new real[][][](2, N, N);
auto dp = new real[][](2, 1 << N);
foreach (h; 0 .. 2) {
foreach (k; 0 .. N) {
prob[h][k][] = 0.0;
}
dp[h][] = 0.0;
dp[h][(1 << N) - 1] = 1.0;
foreach_reverse (s; 1 .. 1 << N) {
const pop = popcnt(s);
const k = N - pop;
const iMin = bsf(s);
if (pop == 1) {
prob[h][k][iMin] += dp[h][s] * 1.0;
dp[h][s ^ 1 << iMin] += dp[h][s] * 1.0;
} else {
prob[h][k][iMin] += dp[h][s] * P[h];
dp[h][s ^ 1 << iMin] += dp[h][s] * P[h];
foreach (i; iMin + 1 .. N) {
if ((s >> i) & 1) {
prob[h][k][i] += dp[h][s] * ((1.0 - P[h]) / (pop - 1));
dp[h][s ^ 1 << i] += dp[h][s] * ((1.0 - P[h]) / (pop - 1));
}
}
}
}
}
debug {
foreach (h; 0 .. 2) {
writefln("h = %s", h);
foreach (k; 0 .. N) {
writefln(" prob[%s][%s] = %s", k, h, prob[h][k]);
}
}
}
real ans = 0.0;
foreach (k; 0 .. N) {
foreach (i0; 0 .. N) foreach (i1; 0 .. N) {
if (A[0][i0] > A[1][i1]) {
ans += prob[0][k][i0] * prob[1][k][i1] * (A[0][i0] + A[1][i1]);
}
}
}
writefln("%.10f", ans);
}
} catch (EOFException e) {
}
}