結果

問題 No.391 CODING WAR
ユーザー kuuso1kuuso1
提出日時 2016-07-08 23:57:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 253 ms / 2,000 ms
コード長 2,231 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 108,352 KB
実行使用メモリ 25,160 KB
最終ジャッジ日時 2023-08-03 10:50:36
合計ジャッジ時間 5,657 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,700 KB
testcase_01 AC 54 ms
20,712 KB
testcase_02 AC 55 ms
20,760 KB
testcase_03 AC 57 ms
20,708 KB
testcase_04 AC 54 ms
20,772 KB
testcase_05 AC 54 ms
22,840 KB
testcase_06 AC 56 ms
20,776 KB
testcase_07 AC 54 ms
20,820 KB
testcase_08 AC 55 ms
20,848 KB
testcase_09 AC 253 ms
24,696 KB
testcase_10 AC 249 ms
24,632 KB
testcase_11 AC 213 ms
24,604 KB
testcase_12 AC 55 ms
20,816 KB
testcase_13 AC 239 ms
22,720 KB
testcase_14 AC 201 ms
23,660 KB
testcase_15 AC 223 ms
24,032 KB
testcase_16 AC 156 ms
24,744 KB
testcase_17 AC 174 ms
25,160 KB
testcase_18 AC 133 ms
22,264 KB
testcase_19 AC 133 ms
22,324 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.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		modComb.Init((int)2e6);
		
		long ans = 0;
		long mod = (long)1e9+7;
		int sig = 1;
		for(long i=M;i>=1;i--){
			long val = modComb.PowMod(i,N);
			val *= modComb.nCrMod(M,i);
			if(val >= mod) val %= mod;
			if(sig == 1) ans += val;
			if(sig == -1) ans += (mod - val);
			if(ans >= mod) ans -= mod;
			
			sig *= -1;
		}
		Console.WriteLine(ans);
		
		
	}
	long N,M;
	public Sol(){
		var d = rla();
		N = d[0];
		M = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

class modComb{
	public static long mod=(long)(1e9+7);
	public static long nCrMod(long n,long r){
		if(n<r)return 0;
		if(n<0)return 0;
		if(r<0)return 0;
		if(n==0||r==n||r==0)return 1;
		long a=FactorialMod(n);
		long b=InvMod(FactorialMod(r));
		long c=InvMod(FactorialMod(n-r));
		long ans=(((a*b)%mod)*c)%mod;
		return ans;
	}
	
	public static long[] FM;
	public static void Init(int sz){
		FM = new long[sz];
	}
	
	public static long FactorialMod(long n){
		
		if(FM[(int)n]!=0)return FM[(int)n];

		if(n<2)return FM[(int)n]=1;
		long ret=n*FactorialMod(n-1);
		ret%=mod;
		return FM[(int)n]=ret;
	}
	
	public static long PowMod(long n,long k){
		
		if(k==0)return 1;
		if(n==0)return 0;
		long ret=1;
		long x=n;
		while(k>0){
			if((k&1)==1){ret*=x;ret%=mod;}
			
			x*=x;x%=mod;
			k>>=1;
		}
		return ret;
		
	}

	public static long InvMod(long n){
		//(mod-2)乗を返す
		// modが素数の時だけ!!!!
		return PowMod(n,mod-2);
	}
	

}
0