結果

問題 No.66 輝け☆全国たこやき杯
ユーザー ぴろずぴろず
提出日時 2015-10-08 13:17:10
言語 Java19
(openjdk 21)
結果
AC  
実行時間 202 ms / 5,000 ms
コード長 805 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 73,924 KB
実行使用メモリ 56,724 KB
最終ジャッジ日時 2023-09-27 08:07:32
合計ジャッジ時間 4,228 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
56,120 KB
testcase_01 AC 115 ms
55,912 KB
testcase_02 AC 118 ms
56,164 KB
testcase_03 AC 119 ms
55,960 KB
testcase_04 AC 121 ms
56,724 KB
testcase_05 AC 125 ms
55,960 KB
testcase_06 AC 130 ms
56,260 KB
testcase_07 AC 137 ms
56,708 KB
testcase_08 AC 184 ms
56,708 KB
testcase_09 AC 202 ms
56,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no93;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = 1 << m;
		double[] s = new double[n];
		for(int i=0;i<n;i++) {
			int x = sc.nextInt();
			s[i] = x * x;
		}
		double[][] p = new double[m+1][n];
		for(int i=0;i<n;i++) {
			p[0][i] = 1D;
		}
		for(int i=0;i<m;i++) {
			for(int j=0;j<(1<<m-1-i);j++) {
				int l1 = (1<<i+1) * j;
				int r1 = l1 + (1 << i);
				int l2 = r1;
				int r2 = l2 + (1 << i);
				for(int k1=l1;k1<l2;k1++) {
					for(int k2=l2;k2<r2;k2++) {
						double p1 = (double) s[k1] / (s[k1] + s[k2]);
						p[i+1][k1] += p[i][k1] * p[i][k2] * p1;
						p[i+1][k2] += p[i][k1] * p[i][k2] * (1 - p1);
					}
				}

			}
		}
		System.out.println(p[m][0]);
	}

}
0