結果

問題 No.173 カードゲーム(Medium)
ユーザー te-shte-sh
提出日時 2016-09-14 16:56:43
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 560 ms / 3,000 ms
コード長 1,014 bytes
コンパイル時間 4,773 ms
コンパイル使用メモリ 174,556 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 22:09:18
合計ジャッジ時間 6,684 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
4,372 KB
testcase_01 AC 62 ms
4,372 KB
testcase_02 AC 438 ms
4,368 KB
testcase_03 AC 434 ms
4,372 KB
testcase_04 AC 416 ms
4,372 KB
testcase_05 AC 347 ms
4,368 KB
testcase_06 AC 271 ms
4,372 KB
testcase_07 AC 236 ms
4,368 KB
testcase_08 AC 230 ms
4,372 KB
testcase_09 AC 560 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
}
0