結果

問題 No.567 コンプリート
ユーザー RisenRisen
提出日時 2017-09-09 00:14:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,702 bytes
コンパイル時間 897 ms
コンパイル使用メモリ 113,560 KB
実行使用メモリ 27,324 KB
最終ジャッジ日時 2024-05-08 11:40:27
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
27,324 KB
testcase_01 AC 30 ms
24,624 KB
testcase_02 AC 32 ms
25,652 KB
testcase_03 AC 35 ms
25,892 KB
testcase_04 AC 32 ms
25,520 KB
testcase_05 AC 33 ms
25,508 KB
testcase_06 AC 33 ms
25,436 KB
testcase_07 AC 32 ms
25,396 KB
testcase_08 AC 32 ms
25,772 KB
testcase_09 AC 31 ms
23,604 KB
testcase_10 AC 32 ms
23,604 KB
testcase_11 AC 30 ms
27,044 KB
testcase_12 AC 32 ms
25,516 KB
testcase_13 AC 30 ms
25,512 KB
testcase_14 AC 32 ms
25,520 KB
testcase_15 AC 24 ms
23,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