結果
| 問題 |
No.117 組み合わせの数
|
| ユーザー |
|
| 提出日時 | 2018-10-08 19:05:36 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,293 bytes |
| コンパイル時間 | 447 ms |
| コンパイル使用メモリ | 66,292 KB |
| 実行使用メモリ | 35,024 KB |
| 最終ジャッジ日時 | 2024-10-12 15:16:17 |
| 合計ジャッジ時間 | 4,304 ms |
|
ジャッジサーバーID (参考情報) |
judge / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
ソースコード
#include<iostream>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
ll modpow(ll a, ll b, ll p = 1e9+7){
if(b == 0) return 1;
if(b % 2 == 0){
ll d = modpow(a, b/2, p);
return (d*d) % p;
}else{
return (a%p * modpow(a, b-1, p)) % p;
}
}
#define N 2000005
ll po[N];
ll inv[N];
int main(){
po[0] = 1;
for(int i = 1; i < N; i++) po[i] = (po[i-1] * i) % mod;
inv[0] = 1;
for(int i = 1; i < N; i++) inv[i] = modpow(po[i], mod-2, mod);
int t;
scanf("%d\n", &t);
char c;
int n, k;
for(int i = 0; i < t; i++){
ll ans = 1;
scanf("%c(%d,%d)\n", &c, &n, &k);
if(c != 'H' && n < k){
printf("0\n");
continue;
}
switch(c){
case 'C':
ans = (ans * po[n]) % mod;
ans = (ans * inv[n-k]) % mod;
ans = (ans * inv[k]) % mod;
break;
case 'P':
ans = (ans * po[n]) % mod;
ans = (ans * inv[n-k]) % mod;
break;
case 'H':
ans = (ans * po[n+k-1]) % mod;
ans = (ans * inv[k]) % mod;
ans = (ans * inv[n+k-1-k]) % mod;
break;
}
printf("%d\n", ans);
}
return 0;
}