結果

問題 No.173 カードゲーム(Medium)
ユーザー fumofumofunifumofumofuni
提出日時 2021-01-22 01:37:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 889 ms / 3,000 ms
コード長 2,382 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 209,256 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-26 17:05:56
合計ジャッジ時間 8,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll p,q;
random_device rnd;     // 非決定的な乱数生成器を生成
mt19937 mt(rnd());     //  メルセンヌ・ツイスタの32ビット版、引数は初期シード値
uniform_int_distribution<> rand1(1,1000);
ll point(set<ll> &a,set<ll> &b){
    if(a.size()==1)return (*a.begin()>*b.begin()? *a.begin()+*b.begin():0);
    ll ret=0;
    ll x,y;
    if(rand1(mt)<=p)x=*a.begin();
    else {
        uniform_int_distribution<> rand2(1,a.size()-1);
        ll k=rand2(mt);
        auto itr=a.begin();rep(i,k)itr++;
        x=*itr;
    }
    if(rand1(mt)<=q)y=*b.begin();
    else {
        uniform_int_distribution<> rand2(1,b.size()-1);
        ll k=rand2(mt);//cout << k <<endl;
        auto itr=b.begin();rep(i,k)itr++;
        y=*itr;
    }
    //cout << x <<" " << y <<endl;
    a.erase(x);b.erase(y);
    return (x>y? x+y+point(a,b):point(a,b));
}
int main(){
    ll n;cin >> n;
    string pp,qq;cin >> pp >> qq;
    p=stoll(pp.substr(2)),q=stoll(qq.substr(2));
    set<ll> a,b;
    ll al=0;
    rep(i,n){
        ll x;cin >> x;a.ins(x);al+=x;
    }
    rep(i,n){
        ll x;cin >> x;b.ins(x);al+=x;
    }
    double win=0,match=0;
    while(true){
        set<ll> aa=a,bb=b;
        ll k=point(aa,bb);
        //cout << k <<endl;
        if(k>al-k)win++;
        match++;
        if(match>=200000)break;
    }
    CST(10);
    cout << win/match <<endl;
}
0