結果
| 問題 | No.117 組み合わせの数 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-17 16:07:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 5,000 ms |
| コード長 | 575 bytes |
| 記録 | |
| コンパイル時間 | 313 ms |
| コンパイル使用メモリ | 23,936 KB |
| 実行使用メモリ | 17,920 KB |
| 最終ジャッジ日時 | 2024-11-22 13:19:09 |
| 合計ジャッジ時間 | 1,054 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
13 | scanf("%lld",&t);
| ~~~~~^~~~~~~~~~~
main.cpp:16:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%*[\n]%c(%lld,%lld)",&c,&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
#define REP(s,n) for(int i=s;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll f[1<<21],n,k,t,s,u,e;char c;
ll inv(ll v){
for(e=mod-2,s=1,u=v%mod;e;u=u*u%mod,e/=2)if(e%2)s=s*u%mod;
return s;
}
ll comb(ll n,ll k){
return n<k||k<0||n<0?0:(f[n]*inv(f[k])%mod)*inv(f[n-k])%mod;}
int main(){
scanf("%lld",&t);
REP(f[0]=1,1<<21)f[i]=f[i-1]*i%mod;
REP(0,t){
scanf("%*[\n]%c(%lld,%lld)",&c,&n,&k);
if(c%2)
k=comb(n,k);
if(c==72)
k=n?comb(n+k-1,k):!k;
if(c==80)
k=n>=k?f[n]*inv(f[n-k])%mod:0;
printf("%lld\n",k);
}
}