結果

問題 No.391 CODING WAR
ユーザー mbanmban
提出日時 2017-01-12 06:16:49
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 2,761 bytes
コンパイル時間 2,114 ms
コンパイル使用メモリ 103,552 KB
実行使用メモリ 23,452 KB
最終ジャッジ日時 2023-08-23 08:37:44
合計ジャッジ時間 5,533 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,736 KB
testcase_01 AC 56 ms
18,708 KB
testcase_02 AC 57 ms
20,644 KB
testcase_03 AC 56 ms
20,784 KB
testcase_04 AC 58 ms
22,764 KB
testcase_05 AC 57 ms
22,776 KB
testcase_06 AC 56 ms
20,824 KB
testcase_07 AC 58 ms
22,852 KB
testcase_08 AC 56 ms
18,844 KB
testcase_09 AC 242 ms
21,524 KB
testcase_10 AC 230 ms
21,600 KB
testcase_11 AC 56 ms
20,892 KB
testcase_12 AC 57 ms
20,840 KB
testcase_13 AC 228 ms
21,632 KB
testcase_14 AC 196 ms
23,400 KB
testcase_15 AC 216 ms
23,452 KB
testcase_16 AC 150 ms
21,124 KB
testcase_17 AC 171 ms
21,276 KB
testcase_18 AC 134 ms
21,044 KB
testcase_19 AC 134 ms
23,200 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;


class Program
{
    static Magatro M = new Magatro();
    static void Main()
    {
        M.Scan();
        M.Solve();
    }
}
class Magatro
{
    private long N, M;
    private const int Mod = 1000000007;
    private long[] Factorial;
    public void Scan()
    {
        Scanner sc = new Scanner();
        N = sc.NextLong();
        M = sc.NextLong();
    }
    public void Solve()
    {
        if (N < M)
        {
            Console.WriteLine(0);
            return;
        }
        FactorialCalc();
        long ans = 0;
        for(int i = 0; i < M; i++)
        {
            int plus;
            if (i % 2 == 0)
            {
                plus = 1;
            }
            else
            {
                plus = -1;
            }
            ans += Converter(plus * MCombination(i) * MyPow(M - i,N,Mod));
        }
        Console.WriteLine(ans%Mod);
    }
    private long Converter(long n)
    {
        n %= Mod;
        if (n < 0) n += Mod;
        return n;
    }
    private long MCombination(long n)
    {
        long bunshi = Factorial[M];
        long bunbo = (Factorial[n] * Factorial[M - n]) % Mod;
        return (bunshi * MyPow(bunbo, Mod - 2, Mod)) % Mod;
    }
    private void FactorialCalc()
    {
        Factorial = new long[M + 1];
        Factorial[0] = 1;
        for(int i = 1; i <= M; i++)
        {
            Factorial[i] = (Factorial[i - 1] * i) % Mod;
        }
    }
    private long MyPow(long a,long b,long mod)
    {
        long result = 1;
        while (b > 0)
        {
            if (b % 2 == 0)
            {
                a = (a * a) % mod;
                b /= 2;
            }
            else
            {
                result = (result * a) % mod;
                b--;
            }
        }
        return result;
    }
}
public class Scanner
{
    private string[] S;
    private int Index;
    private char Separator;
    public Scanner(char separator=' ')
    {
        Index = 0;
        Separator = separator;
    }
    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    }
    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
0