結果

問題 No.2123 Chalk Breaker
ユーザー tentententen
提出日時 2022-11-14 11:26:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 4,378 ms
コンパイル使用メモリ 73,272 KB
実行使用メモリ 53,216 KB
最終ジャッジ日時 2023-10-13 17:46:33
合計ジャッジ時間 6,993 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 335 ms
51,800 KB
testcase_01 AC 336 ms
53,216 KB
testcase_02 AC 176 ms
51,508 KB
testcase_03 AC 107 ms
51,416 KB
testcase_04 AC 44 ms
49,268 KB
testcase_05 AC 292 ms
51,720 KB
testcase_06 AC 110 ms
51,372 KB
testcase_07 AC 141 ms
51,796 KB
testcase_08 AC 99 ms
51,112 KB
testcase_09 AC 42 ms
49,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static double[] dp;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        dp = new double[n + 1];
        Arrays.fill(dp, -1);
        dp[0] = 0;
        System.out.println(dfw(n));
    }
    
    static double dfw(int idx) {
        if (dp[idx] >= 0) {
            return dp[idx];
        }
        dp[idx] = 1;
        for (int i = 0; i < idx; i++) {
            dp[idx] += (dfw(i) + dfw(idx - i - 1)) / idx;
        }
        return dp[idx];
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0