結果

問題 No.173 カードゲーム(Medium)
ユーザー 37zigen37zigen
提出日時 2020-04-19 02:30:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 613 ms / 3,000 ms
コード長 1,430 bytes
コンパイル時間 3,386 ms
コンパイル使用メモリ 78,424 KB
実行使用メモリ 59,084 KB
最終ジャッジ日時 2024-04-14 21:26:04
合計ジャッジ時間 7,460 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
56,432 KB
testcase_01 AC 283 ms
58,236 KB
testcase_02 AC 613 ms
59,048 KB
testcase_03 AC 604 ms
58,860 KB
testcase_04 AC 541 ms
58,560 KB
testcase_05 AC 498 ms
58,876 KB
testcase_06 AC 414 ms
59,084 KB
testcase_07 AC 417 ms
58,772 KB
testcase_08 AC 381 ms
58,544 KB
testcase_09 AC 483 ms
58,620 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	Random rnd=new Random();

	boolean f(int[] A,int[] B,double PA,double PB) {
		int N=A.length;
		int sum=0;
		boolean[] a_used=new boolean[N];
		boolean[] b_used=new boolean[N];
		for (int i=0;i<N;++i) {
			double pa=rnd.nextDouble();
			double pb=rnd.nextDouble();
			int u=0,v=0;
			while (a_used[u]) ++u;
			while (b_used[v]) ++v;
			if (pa>PA && i!=N-1) {
				int k=1+rnd.nextInt(N-1-i);//1...,N-i
				while (k!=0) {
					++u;
					if (!a_used[u]) --k;
				}
			}
			if (pb>PB && i!=N-1) {
				int k=1+rnd.nextInt(N-1-i);
				while (k!=0) {
					++v;
					if (!b_used[v]) --k;
				}
			}
			if (A[u]>B[v]) {
				sum+=A[u]+B[v];
			} else {
				sum-=A[u]+B[v];
			}
			a_used[u]=true;
			b_used[v]=true;
		}
		return sum>0;
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		double PA=sc.nextDouble();
		double PB=sc.nextDouble();
		int[] A=new int[N];
		int[] B=new int[N];
		for (int i=0;i<N;++i) {
			A[i]=sc.nextInt();
		}
		for (int i=0;i<N;++i) {
			B[i]=sc.nextInt();
		}
		Arrays.sort(A);
		Arrays.sort(B);
		int T=100000;
		int wins=0;
		for (int t=0;t<T;++t) { 
			if (f(A,B,PA,PB)) {
				++wins;
			}
		}
		System.out.println(1d*wins/T);
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}
0