結果

問題 No.173 カードゲーム(Medium)
ユーザー koba-e964koba-e964
提出日時 2016-12-13 11:49:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 393 ms / 3,000 ms
コード長 1,335 bytes
コンパイル時間 529 ms
コンパイル使用メモリ 66,664 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 01:43:18
合計ジャッジ時間 3,422 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,376 KB
testcase_01 AC 22 ms
4,376 KB
testcase_02 AC 325 ms
4,380 KB
testcase_03 AC 320 ms
4,376 KB
testcase_04 AC 314 ms
4,380 KB
testcase_05 AC 254 ms
4,384 KB
testcase_06 AC 186 ms
4,376 KB
testcase_07 AC 138 ms
4,376 KB
testcase_08 AC 135 ms
4,380 KB
testcase_09 AC 393 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;

int choice(double p, int n, int bit) {
  int r = __builtin_popcount(bit);
  int cnt = 0;
  if (r == 1) {
    cnt = 0;
  } else {
    if (rand() % 1000 < p * 1000 - 0.5) {
      cnt = 0;
    } else {
      cnt = 1 + (rand() % (r - 1));
    }
  }
  REP(i, 0, n) {
    if (bit & 1 << i) {
      if (cnt == 0) { return i; }
      cnt--;
    }
  }
  assert (0);
}

int main(void){
  int n;
  double p1, p2;
  cin >> n >> p1 >> p2;
  VI a(n), b(n);
  int tot_sc = 0;
  REP(i, 0, n) {
    cin >> a[i];
    tot_sc += a[i];
  }
  REP(i, 0, n) {
    cin >> b[i];
    tot_sc += b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  double tot = 0;
  int num_iteration = 160000;
  REP(iteration, 0, num_iteration) {
    int sc = 0;
    int bita = (1 << n) - 1;
    int bitb = bita;
    REP(i, 0, n) {
      int ca = choice(p1, n, bita);
      int cb = choice(p2, n, bitb);
      bita ^= 1 << ca;
      bitb ^= 1 << cb;
      if (a[ca] > b[cb]) {
	sc += a[ca] + b[cb];
      }
    }
    assert (bita == 0);
    assert (bitb == 0);
    if (sc * 2 > tot_sc) {
      tot += 1;
    }
  }
  printf("%.15f\n", tot / num_iteration);
}
0