結果

問題 No.567 コンプリート
コンテスト
ユーザー Xiaoxiao Deng
提出日時 2025-11-11 15:33:40
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,702 bytes
コンパイル時間 7,986 ms
コンパイル使用メモリ 170,976 KB
実行使用メモリ 187,740 KB
最終ジャッジ日時 2025-11-11 15:33:51
合計ジャッジ時間 10,256 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (106 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class Solution
{
    // nPk
    private static Dictionary<Tuple<int, int>, long> perms = new Dictionary<Tuple<int, int>, long>();
    public static long CalcPermutation(int n, int k)
    {
        var key = Tuple.Create(n, k);
        if (perms.ContainsKey(key))
        {
            return perms[key];
        }

        if (k == 0)
        {
            return 1;
        }
        var v = CalcPermutation(n - 1, k - 1) * n;
        perms[key] = v;
        return v;
    }

    // nCk
    private static Dictionary<Tuple<int, int>, long> combs = new Dictionary<Tuple<int, int>, long>();
    public static long CalcCombination(int n, int k)
    {
        var key = Tuple.Create(n, k);
        if (combs.ContainsKey(key))
        {
            return combs[key];
        }

        var v = CalcPermutation(n, k);
        for (int i = 2; i <= k; i++)
        {
            v /= i;
        }
        combs[key] = v;
        return v;
    }

    static BigInteger GetPattern(int n, int x)
    {
        if (n == 1)
        {
            return 1;
        }

        var pattern = (BigInteger)Math.Pow(n, x);
        for (int i = 1; i < n; i++)
        {
            pattern -= CalcCombination(n, i) * GetPattern(i, x);
        }
        return pattern;
    }

    static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        if (n >= 130)
        {
            Console.WriteLine(1);
            return;
        }

        var allPattern = Math.Pow(6, n);
        var failPattern = GetPattern(6, n);
        var prov = (double)failPattern / allPattern;

        Console.WriteLine(prov);
    }
}
0