結果

問題 No.173 カードゲーム(Medium)
ユーザー parukiparuki
提出日時 2016-09-02 11:21:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 539 ms / 3,000 ms
コード長 1,684 bytes
コンパイル時間 1,846 ms
コンパイル使用メモリ 173,932 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-09 20:26:10
合計ジャッジ時間 5,963 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

random_device rnd;
mt19937 mt(rnd());
uniform_real_distribution<> urd;

vi f(double p, vi A){
    int n = sz(A);
    vi res(n);
    set<int> st(all(A));
    rep(i, n - 1){
        double x = urd(mt);
        if(x <= p){
            res[i] = *st.begin();
            st.erase(st.begin());
        } else{
            x = urd(mt);
            auto it = st.begin();
            ++it;
            double q = 1.0 / (n - i - 1);
            int k = 0;
            while((k + 1)*q <= x-1e-9){
                k++;
                it++;
            }
            res[i] = *it;
            st.erase(it);
        }
    }
    res.back() = *st.begin();
    return res;
}

int main(){
    int N;
    double PA, PB;
    cin >> N >> PA >> PB;
    vi A(N), B(N);
    rep(i, N)scanf("%d", &A[i]);
    rep(i, N)scanf("%d", &B[i]);
    
    const int R = 100000;
    int win = 0;
    rep(hoge, R){
        vi aa = f(PA, A), bb = f(PB, B);

        int sa = 0, sb = 0;
        rep(i, N){
            int s = aa[i] + bb[i];
            if(aa[i] > bb[i])sa += s;
            else sb += s;
        }
        if(sa > sb)win++;
    }

    double ans = (double)win / R;
    printf("%0.20f\n", ans);
}
0