結果

問題 No.173 カードゲーム(Medium)
ユーザー simansiman
提出日時 2022-10-20 07:49:16
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,924 ms / 3,000 ms
コード長 2,622 bytes
コンパイル時間 1,698 ms
コンパイル使用メモリ 106,488 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 15:30:17
合計ジャッジ時間 35,089 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

const ll CYCLE_PER_SEC = 2400000000;
double TIME_LIMIT = 2.8;

unsigned long long int get_cycle() {
  unsigned int low, high;
  __asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
  return ((unsigned long long int) low) | ((unsigned long long int) high << 32);
}

double get_time(unsigned long long int begin_cycle) {
  return (double) (get_cycle() - begin_cycle) / CYCLE_PER_SEC;
}

unsigned long long xor128() {
  static unsigned long long rx = 123456789, ry = 362436069, rz = 521288629, rw = 88675123;
  unsigned long long rt = (rx ^ (rx << 11));
  rx = ry;
  ry = rz;
  rz = rw;
  return (rw = (rw ^ (rw >> 19)) ^ (rt ^ (rt >> 8)));
}

int N;
double PA, PB;
vector<int> A;
vector<int> B;

int simulate(int select_min_rate_a, int select_min_rate_b) {
  bool used_a[N];
  bool used_b[N];
  memset(used_a, false, sizeof(used_a));
  memset(used_b, false, sizeof(used_b));

  int scores[2] = {0, 0};
  int m_idx_a = 0;
  int m_idx_b = 0;

  for (int i = 0; i < N; ++i) {
    int idx_a;
    int idx_b;

    int pa = xor128() % 1000;
    while (used_a[m_idx_a]) {
      ++m_idx_a;
    }
    if (pa < select_min_rate_a || i == N - 1) {
      idx_a = m_idx_a;
    } else {
      do {
        idx_a = xor128() % N;
      } while (used_a[idx_a] || m_idx_a == idx_a);
    }

    int a = A[idx_a];
    used_a[idx_a] = true;

    int pb = xor128() % 1000;
    while (used_b[m_idx_b]) {
      ++m_idx_b;
    }
    if (pb < select_min_rate_b || i == N - 1) {
      idx_b = m_idx_b;
    } else {
      do {
        idx_b = xor128() % N;
      } while (used_b[idx_b] || m_idx_b == idx_b);
    }

    int b = B[idx_b];
    used_b[idx_b] = true;


    if (a > b) {
      scores[0] += a + b;
    } else {
      scores[1] += a + b;
    }
  }

  if (scores[0] > scores[1]) {
    return 1;
  } else if (scores[0] < scores[1]) {
    return 2;
  } else {
    return 0;
  }
}

int main() {
  cin >> N >> PA >> PB;

  A.resize(N);
  B.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N; ++i) {
    cin >> B[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());

  ll start_cycle = get_cycle();
  int play_cnt = 0;
  int ret[3] = {0, 0, 0};
  while (get_time(start_cycle) < TIME_LIMIT) {
    ++play_cnt;
    int s = simulate(PA * 1000, PB * 1000);
    ret[s]++;
  }

  cout << fixed << setprecision(10) << ret[1] * 1.0 / play_cnt << endl;

  return 0;
}
0