結果

問題 No.174 カードゲーム(Hard)
ユーザー GrenacheGrenache
提出日時 2016-07-18 09:47:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 365 ms / 2,000 ms
コード長 2,404 bytes
コンパイル時間 4,972 ms
コンパイル使用メモリ 75,884 KB
実行使用メモリ 76,344 KB
最終ジャッジ日時 2023-09-21 03:00:06
合計ジャッジ時間 8,379 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
56,220 KB
testcase_01 AC 141 ms
55,920 KB
testcase_02 AC 362 ms
76,184 KB
testcase_03 AC 364 ms
75,736 KB
testcase_04 AC 365 ms
75,756 KB
testcase_05 AC 363 ms
76,036 KB
testcase_06 AC 361 ms
75,476 KB
testcase_07 AC 358 ms
75,916 KB
testcase_08 AC 361 ms
76,344 KB
testcase_09 AC 364 ms
76,276 KB
testcase_10 AC 141 ms
57,856 KB
testcase_11 AC 142 ms
55,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder173 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Printer pr = new Printer(System.out);

        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 mask = (0x1 << n) - 1;
        // dpa[i] : iで表されるカードが出された状態になる確率
        double[] dpa = new double[0x1 << n];
        double[] dpb = new double[0x1 << n];
        dpa[0] = 1;
        dpb[0] = 1;
        // aa[i][j] : i番目のカードがj番目に出される確率
        double[][] aa = new double[n][n];
        double[][] bb = new double[n][n];

        for (int i = 0; i < 0x1 << n; i++) {
        	int mini = Integer.numberOfTrailingZeros(~i & mask);
        	for (int j = 0; j < n; j++) {
        		if ((i & 0x1 << j) != 0) {
        			continue;
        		}

        		int k = Integer.bitCount(i);
        		if (k == n - 1) {
        			dpa[i | 0x1 << j] += dpa[i];
        			dpb[i | 0x1 << j] += dpb[i];
            		aa[j][k] += dpa[i];
            		bb[j][k] += dpb[i];
        		} else if (j == mini) {
        			dpa[i | 0x1 << j] += dpa[i] * pa;
        			dpb[i | 0x1 << j] += dpb[i] * pb;
            		aa[j][k] += dpa[i] * pa;
            		bb[j][k] += dpb[i] * pb;
        		} else {
        			dpa[i | 0x1 << j] += dpa[i] * (1 - pa) / (n - k - 1);
        			dpb[i | 0x1 << j] += dpb[i] * (1 - pb) / (n - k - 1);
            		aa[j][k] += dpa[i] * (1 - pa) / (n - k - 1);
            		bb[j][k] += dpb[i] * (1 - pb) / (n - k - 1);
        		}

        	}
        }

        double ret = 0;
        for (int i = 0; i < n; i++) {
        	for (int j = 0; j < n; j++) {
        		if (a[i] <= b[j]) {
        			continue;
        		}

        		for (int k = 0; k < n; k++) {
        			ret += (a[i] + b[j]) * aa[i][k] * bb[j][k];
        		}
        	}
        }

        pr.printf("%.10f\n", ret);

        pr.close();
        sc.close();
    }

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0