結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
fiord
|
| 提出日時 | 2015-08-16 00:14:40 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 778 bytes |
| コンパイル時間 | 1,094 ms |
| コンパイル使用メモリ | 159,456 KB |
| 実行使用メモリ | 81,908 KB |
| 最終ジャッジ日時 | 2024-07-18 09:47:19 |
| 合計ジャッジ時間 | 1,711 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf(" %c(%d,%d)",&s,&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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;
}
fiord