結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
|
| 提出日時 | 2020-02-22 07:59:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 722 bytes |
| コンパイル時間 | 539 ms |
| コンパイル使用メモリ | 67,172 KB |
| 実行使用メモリ | 36,424 KB |
| 最終ジャッジ日時 | 2024-10-09 15:54:22 |
| 合計ジャッジ時間 | 1,611 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#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 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;
}
}