結果

問題 No.58 イカサマなサイコロ
ユーザー sekiya9311
提出日時 2018-02-16 21:18:17
言語 Java
(openjdk 23)
結果
AC  
実行時間 200 ms / 5,000 ms
コード長 2,069 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 83,788 KB
実行使用メモリ 56,892 KB
最終ジャッジ日時 2024-06-22 11:51:55
合計ジャッジ時間 5,377 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Yuki0058 solver = new Yuki0058();
        solver.solve(1, in, out);
        out.close();
    }

    static class Yuki0058 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            Map<Integer, Long> dp = new HashMap<>();
            dp.put(0, 1L);
            for (int cnt = 0; cnt < N; cnt++) {
                Map<Integer, Long> ndp = new HashMap<>();
                int[] taro;
                if (cnt < K) {
                    taro = new int[]{4, 5, 6, 4, 5, 6};
                } else {
                    taro = new int[]{1, 2, 3, 4, 5, 6};
                }
                for (int key : dp.keySet()) {
                    long now = dp.get(key);
                    for (int i = 0; i < 6; i++) {
                        for (int e : taro) {
                            int nxtKey = key + e - (i + 1);
                            long nxtVal = ndp.get(nxtKey) == null ? 0 : ndp.get(nxtKey);
                            ndp.put(nxtKey, nxtVal + now);
                        }
                    }
                }
                dp = ndp;
            }
            double all = 0, win = 0;
            for (int key : dp.keySet()) {
                long val = dp.get(key);
                all += val;
                if (key > 0) {
                    win += val;
                }
            }
            System.err.println(win + " " + all);
            out.println(win / all);
        }

    }
}

0