結果

問題 No.58 イカサマなサイコロ
ユーザー sekiya9311sekiya9311
提出日時 2018-02-16 21:18:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 194 ms / 5,000 ms
コード長 2,069 bytes
コンパイル時間 2,822 ms
コンパイル使用メモリ 92,736 KB
実行使用メモリ 56,896 KB
最終ジャッジ日時 2023-09-04 13:21:53
合計ジャッジ時間 5,254 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
56,656 KB
testcase_01 AC 190 ms
56,572 KB
testcase_02 AC 165 ms
56,608 KB
testcase_03 AC 166 ms
56,884 KB
testcase_04 AC 191 ms
56,792 KB
testcase_05 AC 191 ms
56,512 KB
testcase_06 AC 193 ms
56,520 KB
testcase_07 AC 166 ms
56,692 KB
testcase_08 AC 167 ms
56,708 KB
testcase_09 AC 194 ms
56,896 KB
権限があれば一括ダウンロードができます

ソースコード

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