結果

問題 No.173 カードゲーム(Medium)
コンテスト
ユーザー kotatsugame
提出日時 2020-03-04 13:27:05
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,091 ms / 3,000 ms
コード長 1,044 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,197 ms
コンパイル使用メモリ 118,256 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-02-19 21:29:50
合計ジャッジ時間 7,795 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #
raw source code

#include<iostream>
#include<random>
#include<vector>
#include<algorithm>
#include<iomanip>
using namespace std;
int N;
int PA,PB;
main()
{
	cin>>N;
	double pa,pb;
	cin>>pa>>pb;
	PA=pa*1e6;
	PB=pb*1e6;
	vector<int>A(N),B(N);
	for(int&a:A)cin>>a;
	for(int&b:B)cin>>b;
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	mt19937 rng(114514);
	int wc=0;
	const int TM=1e6;
	for(int c=0;c<TM;c++)
	{
		vector<int>a=A,b=B;
		int as=0,bs=0;
		for(int i=0;i<N;i++)
		{
			if(i+1==N)
			{
				if(a[0]<b[0])bs+=a[0]+b[0];
				else as+=a[0]+b[0];
			}
			else
			{
				int A,B;
				int at=rng()%TM;
				if(at<PA)
				{
					A=a[0];
					a.erase(a.begin());
				}
				else
				{
					int id=rng()%(N-i-1)+1;
					A=a[id];
					a.erase(a.begin()+id);
				}
				int bt=rng()%TM;
				if(bt<PB)
				{
					B=b[0];
					b.erase(b.begin());
				}
				else
				{
					int id=rng()%(N-i-1)+1;
					B=b[id];
					b.erase(b.begin()+id);
				}
				if(A<B)bs+=A+B;
				else as+=A+B;
			}
		}
		if(as>bs)wc++;
	}
	cout<<fixed<<setprecision(16)<<wc/(double)TM<<endl;
}
0