結果

問題 No.173 カードゲーム(Medium)
ユーザー ttkkggww
提出日時 2022-08-19 04:19:29
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,408 bytes
コンパイル時間 16,816 ms
コンパイル使用メモリ 326,392 KB
最終ジャッジ日時 2025-01-31 00:04:09
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
int n;
double pa,pb;
vector<int> A,B;
chrono::time_point<chrono::system_clock> start;
int getTime() {
	return chrono::duration_cast<chrono::microseconds>(chrono::system_clock::now()-start).count();
}

double rand01(){
	return (double)rand()/RAND_MAX;
}

void solve(){
	std::random_device seed_gen;
  std::default_random_engine engine(seed_gen());
	std::uniform_int_distribution<> dist(0,232792560 );
	sort(A.rbegin(),A.rend());
	sort(B.rbegin(),B.rend());
	double win = 0,game= 0;
	while(getTime()<2'990'000){
		auto C = A,D = B;
		int Csum = 0,Dsum = 0;
		for(int i = 0;i<n;i++){
			int Ccur,Dcur;
			if(rand01()<pa||C.size()==1){
				Ccur = C.back();
				C.pop_back();
			}else{
				int idx = dist(engine)%(C.size()-1);
				Ccur = C[idx];
				C.erase(C.cbegin()+idx);
			}
			if(rand01()<pb||D.size()==1){
				Dcur = D.back();
				D.pop_back();
			}else{
				int idx = dist(engine)%(D.size()-1);
				Dcur = D[idx];
				D.erase(D.cbegin()+idx);
			}
			if(Ccur>Dcur)Csum += Ccur+Dcur;
			else Dsum += Dcur+Ccur;
		}
		if(Csum>Dsum)win++;
		game++;
	}
	printf("%.10lf\n",win/game);
}
signed main(){start = chrono::system_clock::now();
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n >> pa >> pb;
	A = B = vector<int>(n);
	for(auto &i:A)cin >> i;
	for(auto &i:B)cin >> i;
	solve();
}
0