結果
| 問題 |
No.117 組み合わせの数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-15 02:28:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 236 ms / 5,000 ms |
| コード長 | 1,788 bytes |
| コンパイル時間 | 1,577 ms |
| コンパイル使用メモリ | 167,868 KB |
| 実行使用メモリ | 19,032 KB |
| 最終ジャッジ日時 | 2024-10-15 00:29:17 |
| 合計ジャッジ時間 | 2,217 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:76:21: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
76 | if(a==0 && b==0) ans=1;
| ~~~~~^~~~~~~
main.cpp:41:14: note: 'b' was declared here
41 | ll a,b;
| ^
main.cpp:76:21: warning: 'a' may be used uninitialized [-Wmaybe-uninitialized]
76 | if(a==0 && b==0) ans=1;
| ~~~~~^~~~~~~
main.cpp:41:12: note: 'a' was declared here
41 | ll a,b;
| ^
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const ll mod=1e9+7;
ll mod_inv(ll x)
{
ll pw[32];
pw[0]=x;
for(int i=1; i<32; ++i) pw[i]=(pw[i-1]*pw[i-1])%mod;
ll ret=1;
ll p=mod-2;
rep(i,32) if(p>>i&1) (ret*=pw[i])%=mod;
return ret;
}
ll fact[2000000]={0};
int main()
{
fact[0]=1;
for(ll i=1; i<2000000; ++i) fact[i]=(fact[i-1]*i)%mod;
int TIMES;
cin >>TIMES;
rep(T,TIMES)
{
string s;
cin >>s;
ll a,b;
for(int i=2; i<s.size(); ++i)
{
if(s[i]==',')
{
a=atoll(s.substr(2,i-2).c_str());
b=atoll(s.substr(i+1,s.size()-i-1).c_str());
break;
}
}
//printf("a=%lld, b=%lld\n", a,b);
ll ans=1;
if(s[0]=='C')
{
if(a<b) ans=0;
else
{
ans=fact[a];
(ans*=mod_inv(fact[b]))%=mod;
(ans*=mod_inv(fact[a-b]))%=mod;
}
}
else if(s[0]=='P')
{
if(a<b) ans=0;
else
{
ans=fact[a];
(ans*=mod_inv(fact[a-b]))%=mod;
}
}
else
{
if(a==0 && b==0) ans=1;
else
{
ans=fact[a+b-1];
(ans*=mod_inv(fact[b]))%=mod;
(ans*=mod_inv(fact[a-1]))%=mod;
}
}
cout << ans << endl;
}
return 0;
}