結果

問題 No.567 コンプリート
ユーザー RisenRisen
提出日時 2017-09-09 00:14:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 1,702 bytes
コンパイル時間 3,914 ms
コンパイル使用メモリ 104,392 KB
実行使用メモリ 25,380 KB
最終ジャッジ日時 2023-08-21 06:07:41
合計ジャッジ時間 4,381 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
23,140 KB
testcase_01 AC 66 ms
25,236 KB
testcase_02 AC 67 ms
23,040 KB
testcase_03 AC 68 ms
23,000 KB
testcase_04 AC 68 ms
23,236 KB
testcase_05 AC 69 ms
23,132 KB
testcase_06 AC 68 ms
21,116 KB
testcase_07 AC 66 ms
21,308 KB
testcase_08 AC 69 ms
23,208 KB
testcase_09 AC 69 ms
25,172 KB
testcase_10 AC 69 ms
23,136 KB
testcase_11 AC 65 ms
21,100 KB
testcase_12 AC 68 ms
23,144 KB
testcase_13 AC 67 ms
23,328 KB
testcase_14 AC 69 ms
25,380 KB
testcase_15 AC 56 ms
20,848 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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