結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-10 03:57:47 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,701 bytes |
| コンパイル時間 | 2,992 ms |
| コンパイル使用メモリ | 164,736 KB |
| 実行使用メモリ | 173,184 KB |
| 最終ジャッジ日時 | 2024-06-13 02:29:23 |
| 合計ジャッジ時間 | 8,203 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 TLE * 1 -- * 7 |
ソースコード
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)); }
class XRand {
uint x = 314159265, y = 358979323, z = 846264338, w = 327950288;
void setSeed(uint seed) { w ^= seed * 65535; }
uint next() { uint t = x ^ x << 11; x = y; y = z; z = w; return w = w ^ w >> 19 ^ t ^ t >> 8; }
uint nextInt(uint m) { return next() % m; }
int nextInt(int a, int b) { return a + nextInt(b - a + 1); }
real nextReal() { return next() / 4294967296.0; }
}
immutable NUM_TRIES = 10^^6;
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 seq = new int[][1 << N];
foreach (s; 0 .. 1 << N) {
foreach (i; 0 .. N) {
if ((s >> i) & 1) {
seq[s] ~= i;
}
}
}
auto rng = new XRand();
real nmr = 0.0;
foreach (_; 0 .. NUM_TRIES) {
int score;
auto s = new int[2];
s[] = (1 << N) - 1;
foreach (k; 0 .. N) {
const pop = N - k;
auto a = new int[2];
foreach (h; 0 .. 2) {
const pos = (pop == 1) ? 0 : (rng.nextReal() < P[h]) ? 0 : rng.nextInt(1, pop - 1);
const i = seq[s[h]][pos];
s[h] ^= 1 << i;
a[h] = A[h][i];
}
score += ((a[0] < a[1]) ? -1 : +1) * (a[0] + a[1]);
}
if (score > 0) {
nmr += 1.0;
}
}
writefln("%.10f", nmr / NUM_TRIES);
}
} catch (EOFException e) {
}
}