結果

問題 No.173 カードゲーム(Medium)
ユーザー なおなお
提出日時 2015-03-27 00:33:39
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,516 ms / 3,000 ms
コード長 1,721 bytes
コンパイル時間 1,374 ms
コンパイル使用メモリ 150,152 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-11 10:35:50
合計ジャッジ時間 29,910 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define REP(i, n)           for(int(i)=0;(i)<(n);++(i))
#define FOR(i, f, t)        for(int(i)=(f);(i)<(t);(++i))
#define RREP(i, n)          for(int(i)=(n)-1;(i)>=0;--(i))
const int MOD = int(1e9+7);

int N;
double Pa,Pb;
int a[22],b[22];
int res = 0;

unsigned int xor128(void) {
    static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
    unsigned int t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}

int main(){
    do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0);
    cin >> N >> Pa >> Pb;

    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    sort(a,a+N);
    sort(b,b+N);

    int win = 0, total = 0;
    clock_t t = clock() + CLOCKS_PER_SEC * 2.5;
    while(t >= clock()){
        ll sa = 0, sb = 0;
        VI aa(a,a+N), bb(b,b+N);
        REP(i,N){
            int ka,kb;
            double x = xor128()%1000/1000.;
            if(aa.size() == 1 || x<Pa){
                ka = aa[0], aa.erase(aa.begin());
            } else {
                int j = xor128() % (aa.size()-1);
                ka = aa[j+1]; aa.erase(aa.begin()+j+1);
            }
            x = xor128()%1000/1000.;
            if(bb.size() == 1 || x<Pb){
                kb = bb[0], bb.erase(bb.begin());
            } else {
                int j = xor128() % (bb.size()-1);
                kb = bb[j+1]; bb.erase(bb.begin()+j+1);
            }
            if(ka > kb) sa += ka+kb; else sb += ka+kb;
        }
        if(sa > sb) win++;
        total++;
    }
    cout << fixed << setprecision(15) << 1. * win / total << endl;
    return 0;
}
0