結果
| 問題 |
No.173 カードゲーム(Medium)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-09-14 16:56:43 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 571 ms / 3,000 ms |
| コード長 | 1,014 bytes |
| コンパイル時間 | 3,529 ms |
| コンパイル使用メモリ | 175,960 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 04:23:02 |
| 合計ジャッジ時間 | 6,620 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 |
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;
const auto rep = 10 ^^ 5;
void main()
{
auto rd = readln.split;
auto n = rd[0].to!size_t, pa = rd[1].to!real, pb = rd[2].to!real;
auto ai = readln.split.map!(to!int).array;
auto bi = readln.split.map!(to!int).array;
ai.sort();
bi.sort();
auto r = 0;
foreach (_; 0..rep) {
auto wa = 0, wb = 0;
auto aj = ai.dup, bj = bi.dup;
foreach (i; 0..n) {
int a = pickup(aj, pa);
int b = pickup(bj, pb);
if (a > b) wa += a + b;
else wb += a + b;
}
if (wa > wb) r += 1;
}
writeln(r.to!real / rep);
}
int pickup(ref int[] ai, real p)
{
int a;
if (ai.length == 1 || uniform(0.0L, 1.0L) <= p) {
a = ai.front;
ai = ai[1..$];
} else {
auto i = uniform(1, ai.length);
a = ai[i];
ai = ai[0..i] ~ ai[i+1..ai.length];
}
return a;
}