結果

問題 No.1035 Color Box
ユーザー bluemeganebluemegane
提出日時 2020-04-29 07:40:02
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,151 bytes
コンパイル時間 1,413 ms
コンパイル使用メモリ 67,460 KB
実行使用メモリ 22,896 KB
最終ジャッジ日時 2023-08-18 08:07:50
合計ジャッジ時間 5,394 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
20,728 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 58 ms
20,708 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 AC 58 ms
22,724 KB
testcase_17 AC 57 ms
20,740 KB
testcase_18 WA -
testcase_19 AC 61 ms
20,828 KB
testcase_20 AC 59 ms
22,712 KB
testcase_21 AC 58 ms
20,952 KB
testcase_22 AC 58 ms
20,752 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 58 ms
20,744 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 59 ms
22,740 KB
testcase_31 AC 57 ms
20,728 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;
        if (m < n)
        {
            var t = getInv(2, MOD);
            ans *= t;
            ans %= MOD;
        }
        Console.WriteLine(ans);
    }
    public static long getInv(int a, int m)
    {
        var x = 0L; var y = 1L; var gcd = (long)m;
        var px = 1L; var py = 0L; var pgcd = (long)a;
        var temp = 0L;

        while (gcd > 0)
        {
            var quotient = pgcd / gcd;

            temp = x;
            x = px - quotient * temp;
            px = temp;

            temp = y;
            y = py - quotient * temp;
            py = temp;

            temp = gcd;
            gcd = pgcd - quotient * temp;
            pgcd = temp;
        }

        return px < 0 ? px + m : px;
    }

}
0