結果

問題 No.117 組み合わせの数
ユーザー kotatsugamekotatsugame
提出日時 2020-02-22 17:16:02
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 256 ms / 5,000 ms
コード長 729 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 66,036 KB
実行使用メモリ 36,188 KB
最終ジャッジ日時 2024-04-17 23:48:46
合計ジャッジ時間 1,448 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 256 ms
36,188 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
long mod=1e9+7,F[2<<20],I[2<<20];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long P(int N,int K){return N<K?0:F[N]*I[N-K]%mod;}
long C(int N,int K){return K==0?1:N<K?0:F[N]*I[N-K]%mod*I[K]%mod;}
long H(int N,int K){return C(N-1+K,K);}
main()
{
	F[0]=1;
	for(int i=1;i<2<<20;i++)F[i]=F[i-1]*i%mod;
	I[(2<<20)-1]=power(F[(2<<20)-1],mod-2);
	for(int i=(2<<20)-1;i--;)I[i]=I[i+1]*-~i%mod;
	int T;cin>>T;
	for(;T--;)
	{
		string s;cin>>s;
		char op=s[0];
		int id=2;
		int N=0,K=0;
		while(s[id]!=',')
		{
			N=N*10+s[id]-'0';
			id++;
		}
		id++;
		while(s[id]!=')')
		{
			K=K*10+s[id]-'0';
			id++;
		}
		cout<<(op=='C'?C(N,K):op=='P'?P(N,K):H(N,K))<<endl;
	}
}
0