結果

問題 No.1035 Color Box
ユーザー O2MT
提出日時 2021-11-26 14:30:48
言語 C#
(.NET 8.0.404)
結果
WA  
実行時間 -
コード長 1,012 bytes
コンパイル時間 12,463 ms
コンパイル使用メモリ 165,280 KB
実行使用メモリ 185,272 KB
最終ジャッジ日時 2024-06-29 11:13:44
合計ジャッジ時間 15,162 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (98 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using System.Linq;
using System.Numerics;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
            var (N, M) = (arr[0], arr[1]);
            var MOD = (long)Math.Pow(10, 9) + 7;
            long ans;
            if (N == M)
            {
                ans = nPk(N, M - 1, MOD);
            }
            else
            {
                ans = (long)(nPk(N, M, MOD) * BigInteger.ModPow((N - M), M, MOD) % MOD);
            }
           
            Console.WriteLine(ans);
        }

        /// <summary>
        /// 順列 (n >= k)
        /// </summary>
        public static long nPk(long n, long k, long mod)
        {
            if (n < k) return 0;
            if (n == k) return 1;

            long x = 1;
            for (long i = 0; i < k; i++)
            {
                x = x * (n - i) % mod;
            }
            return x;
        }
    }
}
0