結果

問題 No.117 組み合わせの数
コンテスト
ユーザー koba-e964
提出日時 2016-10-17 16:07:48
言語 C++11
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 84 ms / 5,000 ms
+ 657µs
コード長 575 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 120 ms
コンパイル使用メモリ 41,612 KB
実行使用メモリ 20,176 KB
最終ジャッジ日時 2026-09-28 04:03:07
合計ジャッジ時間 1,673 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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);
  }
}
0