結果

問題 No.173 カードゲーム(Medium)
ユーザー te-shte-sh
提出日時 2018-07-13 15:57:01
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 421 ms / 3,000 ms
コード長 1,250 bytes
コンパイル時間 2,250 ms
コンパイル使用メモリ 160,112 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 20:44:44
合計ジャッジ時間 5,035 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
4,380 KB
testcase_01 AC 49 ms
4,380 KB
testcase_02 AC 302 ms
4,376 KB
testcase_03 AC 302 ms
4,380 KB
testcase_04 AC 288 ms
4,376 KB
testcase_05 AC 221 ms
4,380 KB
testcase_06 AC 153 ms
4,380 KB
testcase_07 AC 119 ms
4,384 KB
testcase_08 AC 115 ms
4,376 KB
testcase_09 AC 421 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;
import std.random;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

const iter = 100_000;

void main()
{
  int n; real pa, pb; readV(n, pa, pb);
  int[] a; readA(n, a);
  int[] b; readA(n, b);

  a.sort();
  b.sort();

  auto calc()
  {
    auto decide(ref int[] a, real p)
    {
      if (a.length == 1) {
        auto r = a[0];
        a = [];
        return r;
      }

      auto q = uniform01;
      if (q < p) {
        auto r = a[0];
        a = a[1..$];
        return r;
      } else {
        auto i = uniform(1, a.length);
        auto r = a[i];
        a = a[0..i] ~ a[i+1..$];
        return r;
      }
    }

    auto da = a.dup, db = b.dup, sa = 0, sb = 0;

    foreach (_; 0..n) {
      auto ca = decide(da, pa), cb = decide(db, pb);
      if (ca > cb)      sa += ca+cb;
      else if (ca < cb) sb += ca+cb;
    }

    return sa > sb;
  }

  auto r = 0;
  foreach (_; 0..iter) r += calc;

  writefln("%.4f", r.to!real/iter);
}
0