結果

問題 No.173 カードゲーム(Medium)
ユーザー 👑 hos.lyrichos.lyric
提出日時 2019-04-01 20:50:53
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 2,089 ms / 3,000 ms
コード長 2,705 bytes
コンパイル時間 2,473 ms
コンパイル使用メモリ 162,284 KB
実行使用メモリ 148,276 KB
最終ジャッジ日時 2023-09-04 00:10:24
合計ジャッジ時間 18,077 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
4,376 KB
testcase_01 AC 110 ms
4,376 KB
testcase_02 AC 1,982 ms
146,908 KB
testcase_03 AC 1,905 ms
147,012 KB
testcase_04 AC 1,879 ms
147,152 KB
testcase_05 AC 1,802 ms
146,664 KB
testcase_06 AC 1,654 ms
148,276 KB
testcase_07 AC 1,618 ms
148,172 KB
testcase_08 AC 1,646 ms
146,888 KB
testcase_09 AC 2,089 ms
147,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 = 2 * 10^^5;

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) {
  }
}
0