結果

問題 No.66 輝け☆全国たこやき杯
ユーザー takeya_okinotakeya_okino
提出日時 2017-07-08 17:03:12
言語 Java21
(openjdk 21)
結果
AC  
実行時間 257 ms / 5,000 ms
コード長 1,109 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 77,740 KB
実行使用メモリ 42,684 KB
最終ジャッジ日時 2024-04-16 06:25:59
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
41,364 KB
testcase_01 AC 121 ms
40,028 KB
testcase_02 AC 121 ms
40,112 KB
testcase_03 AC 122 ms
40,392 KB
testcase_04 AC 130 ms
40,508 KB
testcase_05 AC 154 ms
41,584 KB
testcase_06 AC 159 ms
41,584 KB
testcase_07 AC 170 ms
41,728 KB
testcase_08 AC 229 ms
42,140 KB
testcase_09 AC 257 ms
42,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int M = sc.nextInt();
    int[] s = new int[(int)Math.pow(2, M) + 1];
    for(int i = 1; i < s.length; i++) {
      s[i] = sc.nextInt();
    }
    int num = s.length;
    // dp[j][i]は選手iがj回戦に勝つ確率
    double[][] dp = new double[M + 1][num];
    for(int i = 1; i < num; i++) {
      int aite = i + 1;
      if(i % 2 == 0) aite = i - 1;
      dp[1][i] = (double)(s[i] * s[i]) / (double)(s[i] * s[i] + s[aite] * s[aite]);
    }
    for(int j = 2; j <= M; j++) {
      for(int i = 1; i < num; i++) {
        int k = (i + (int)Math.pow(2, j - 1) - 1) / (int)Math.pow(2, j - 1);
        int aite = k + 1;
        if(k % 2 == 0) aite = k - 1;
        double p = 0;
        for(int l = (int)Math.pow(2, j - 1) * (aite - 1) + 1; l <= (int)Math.pow(2, j - 1) * aite; l++) {
          p += (dp[j - 1][l] * ((double)(s[i] * s[i]) / (double)(s[i] * s[i] + s[l] * s[l])));
        }
        dp[j][i] = dp[j - 1][i] * p;
      }
    }
    System.out.println(dp[M][1]);
  }
}
0