結果

問題 No.1035 Color Box
ユーザー bluemeganebluemegane
提出日時 2020-04-29 07:24:39
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,463 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 67,308 KB
実行使用メモリ 24,972 KB
最終ジャッジ日時 2023-08-18 07:45:38
合計ジャッジ時間 6,387 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 59 ms
20,736 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 60 ms
22,804 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 61 ms
22,792 KB
testcase_20 AC 58 ms
20,792 KB
testcase_21 WA -
testcase_22 AC 57 ms
20,792 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 58 ms
22,828 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 58 ms
20,796 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;

class Modulo
{
    private const int MOD = 1000000007;
    private readonly int[] m_facs;
    public int Mul(int a, int b) => (int)(Math.BigMul(a, b) % MOD);
    public Modulo(int n)
    {
        m_facs = new int[n + 1];
        m_facs[0] = 1;
        for (int i = 1; i <= n; ++i)
            m_facs[i] = Mul(m_facs[i - 1], i);
    }
    public int Fac(int n) => m_facs[n];
    public int Pow(int a, int m)
    {
        switch (m)
        {
            case 0:
                return 1;
            case 1:
                return a;
            default:
                int p1 = Pow(a, m / 2);
                int p2 = Mul(p1, p1);
                return ((m % 2) == 0) ? p2 : Mul(p2, a);
        }
    }
    public int Div(int a, int b) => Mul(a, Pow(b, MOD - 2));
    public int Ncr(int n, int r)
    {
        if (n < r) return 0;
        if (n == r) return 1;
        int res = Fac(n);
        res = Div(res, Fac(r));
        res = Div(res, Fac(n - r));
        return res;
    }
}


public class Hello
{
    static int MOD = 1000000007;
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var md = new Modulo(n);
        var t1 = md.Ncr(n, m);
        var t2 = md.Fac(m);
        var t3 = md.Pow(m, n - m);
        long ans = (t1 * t2) % MOD;
        ans *= t3;
        ans %= MOD;
        Console.WriteLine(ans);
    }
}
0