結果
| 問題 |
No.117 組み合わせの数
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-09-25 11:02:54 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 299 ms / 5,000 ms |
| コード長 | 2,031 bytes |
| コンパイル時間 | 1,717 ms |
| コンパイル使用メモリ | 169,744 KB |
| 実行使用メモリ | 34,688 KB |
| 最終ジャッジ日時 | 2024-12-22 12:49:14 |
| 合計ジャッジ時間 | 2,675 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 1 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:101:11: warning: 'Res' may be used uninitialized [-Wmaybe-uninitialized]
101 | printf("%lld\n", Res);
| ~~~~~~^~~~~~~~~~~~~~~
main.cpp:95:8: note: 'Res' was declared here
95 | ll Res;
| ^~~
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i = a; i < b; i++)
#define repl(i,a,b) for(ll i = a; i < b; i++)
#define REP(i,a,b) for(int i = a; i <=b; i++)
#define REPL(i,a,b) for(ll i = a; i <=b; i++)
#define fore(i,a) for(auto &i : a)
#define all(x) (x).begin(),(x).end()
#define fix(i) fixed << setprecision(i)
#define nextp(v) next_permutation(all(v))
template<class T>bool chmax(T& a, const T& b) { if(a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if(b < a) { a = b; return 1; } return 0; }
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pq = priority_queue<int>;
using pqll = priority_queue<ll>;
const ll INF = LLONG_MAX/2;
const ll MOD = 1000000007;
struct Comb {
vector<ll> fact, rfact;
ll inv(int X) {
ll Res = 1, K = MOD-2, Y = X;
while(K) {
if(K & 1) Res = (Res * Y) % MOD;
Y = (Y * Y) % MOD;
K /= 2;
}
return Res;
}
Comb(int N) {
fact.resize(N);
fact[0] = 1;
rep(i,1,N) fact[i] = fact[i-1]*i % MOD;
rfact.resize(N);
rfact[N-1] = inv(fact[N-1]);
for(int i = N-2; i >= 0; i--) rfact[i] = (rfact[i+1] * (i+1)) % MOD;
}
ll C(int N, int K) {
if (K < 0 || N < K) return 0;
ll A = fact[N], B = rfact[N-K], C = rfact[K];
ll BC = (B * C) % MOD;
return (A * BC) % MOD;
}
ll P(int N, int K) {
if (K < 0 || N < K) return 0;
ll A = fact[N], B = rfact[N-K];
return (A * B) % MOD;
}
ll H(int N, int K) {
if (N == 0 && K == 0) return 1;
return C(N+K-1, K);
}
};
int main() {
int N; cin >> N;
Comb combo(2000001);
rep(i,0,N) {
char Type, Ignore; int A, B;
cin >> Type >> Ignore >> A >> Ignore >> B >> Ignore;
ll Res;
if(Type == 'C') Res = combo.C(A, B);
else if(Type == 'P') Res = combo.P(A, B);
else if(Type == 'H') Res = combo.H(A, B);
printf("%lld\n", Res);
}
}