結果

問題 No.117 組み合わせの数
コンテスト
ユーザー fiord
提出日時 2015-08-16 00:14:40
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 778 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,040 ms
コンパイル使用メモリ 176,400 KB
実行使用メモリ 258,300 KB
最終ジャッジ日時 2026-04-02 01:36:57
合計ジャッジ時間 1,708 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define E 1000000007
ll res[10000000];
ll calc(ll a,int b=E-2){
	long long int ans=1;
	while(b){
		if(b&1)	ans=(ans*a)%E;
		a=(a*a)%E;
		b>>=1;
	}
	return ans;
}
ll ncm(ll n,ll m){
	return (res[n]*calc(res[m])%E)*calc(res[n-m])%E;
}
int main(){
	res[0]=res[1]=1;
	for(int i=2;i<10000000;i++)	res[i]=i*res[i-1]%E;
	int t;	cin>>t;
	while(t--){
		int n,k;
		char s;
		scanf(" %c(%d,%d)",&s,&n,&k);
		if(n<k&&s!='H'){
			cout<<0<<endl;
			continue;
		}
		switch(s){
			case 'C':
				printf("%lld\n",ncm(n,k));
				break;
			case 'P':
				printf("%lld\n",(ll)res[n]*calc(res[n-k])%E);
				break;
			case 'H':
				if(n+k==0)	cout<<0<<endl;
				else 	printf("%lld\n",ncm(n+k-1,k));
				break;
		}
	}
	return 0;
}
0