結果
| 問題 |
No.117 組み合わせの数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-07-04 11:43:58 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,469 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 67,584 KB |
| 実行使用メモリ | 20,864 KB |
| 最終ジャッジ日時 | 2024-09-19 03:54:38 |
| 合計ジャッジ時間 | 2,269 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 1 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
58 | scanf(" %c(%d,%d)",&c[i] ,&a[i] ,&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
int T;
const int MAX = 1000000;
const ll MOD = pow(10,9)+7;
vector<ll> fct(1000001);
vector<ll> invfct(1000001);
ll mpow(ll x, ll n){ //x^n(mod M)
ll ans = 1;
while(n != 0){
if(n&1) ans = ans*x % MOD;
x = x*x % MOD;
n = n >> 1;
}
return ans;
}
ll comb(ll a, ll b){ //aCb(mod M)
if(a == 0 && b == 0)return 1;
if(a < b || a < 0)return 0;
ll tmp = invfct[a-b]* invfct[b] % MOD;
return tmp * fct[a] % MOD;
}
ll perm(ll a, ll b){
if(a < b) return 0;
ll tmp = invfct[a-b] % MOD;
return tmp * fct[a] % MOD;
}
ll dupc(ll a,ll b){
if(a == 0 && b == 0)return 1;
if(a < 0 || b == 0)return 0;
ll tmp = invfct[a-1]* invfct[b] % MOD;
return tmp * fct[a+b-1] % MOD;
}
int main(void){
// Your code here!
fct[0] = 1;
invfct[0] = 1;
for(ll i = 0; i < 1000000; i++){
fct[i+1] = fct[i] * (i+1) % MOD;
invfct[i+1] = invfct[i] * mpow(i+1, MOD-2) % MOD;
}
cin >> T;
vector<char> c(T);
vector<int> a(T),b(T);
for(int i = 0; i < T; i++){
scanf(" %c(%d,%d)",&c[i] ,&a[i] ,&b[i]);
}
for(int i =0 ; i < T; i++){
ll ans = 0;
if(c[i] == 'P') ans = perm(a[i], b[i]);
if(c[i] == 'H') ans = dupc(a[i], b[i]);
if(c[i] == 'C') ans = comb(a[i], b[i]);
cout << ans << endl;
}
return 0;
}