結果
| 問題 | No.117 組み合わせの数 |
| コンテスト | |
| ユーザー |
kcm1700
|
| 提出日時 | 2015-01-04 23:39:33 |
| 言語 | C++11 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 5,000 ms |
| コード長 | 1,225 bytes |
| 記録 | |
| コンパイル時間 | 470 ms |
| コンパイル使用メモリ | 67,980 KB |
| 実行使用メモリ | 27,236 KB |
| 最終ジャッジ日時 | 2026-03-05 21:45:41 |
| 合計ジャッジ時間 | 690 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
ソースコード
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int mod = 1000000007;
int inv[2000003];
int fact[2000003];
int ifact[2000003];
int main()
{
int T;
inv[1] = 1;
for (int i = 2; i <= 2000000; i++) {
inv[i] = (long long)(mod - mod / i) * inv[mod%i] % mod;
}
fact[0] = 1;
for (int i = 1; i <= 2000000; i++) fact[i] = fact[i-1] * (long long)i % mod;
ifact[0] = 1;
for (int i = 1; i <= 2000000; i++) ifact[i] = ifact[i-1] * (long long)inv[i] % mod;
scanf("%d",&T);
while(T-->0){
char front[30];
int n,k;
scanf("%2s%d,%d%*s",front, &n,&k);
long long ans = 0;
if (front[0] == 'C') {
if (n < k) ans = 0;
else {
ans = fact[n];
ans *= ifact[k]; ans %= mod;
ans *= ifact[n-k]; ans %= mod;
}
} else if (front[0] == 'P') {
if (n-k < 0) ans = 0;
else {
ans = fact[n];
ans *= ifact[n-k]; ans %= mod;
}
} else if (front[0] == 'H') {
if (n == 0 && k == 0) {
ans = 1;
} else {
ans = fact[n+k-1];
ans *= ifact[k]; ans %= mod;
ans *= ifact[n-1]; ans %= mod;
}
}
printf("%lld\n", ans);
}
return 0;
}
kcm1700