結果
問題 | No.117 組み合わせの数 |
ユーザー | kazuma |
提出日時 | 2017-09-03 12:20:32 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,258 bytes |
コンパイル時間 | 2,104 ms |
コンパイル使用メモリ | 202,792 KB |
実行使用メモリ | 50,280 KB |
最終ジャッジ日時 | 2024-11-06 19:58:48 |
合計ジャッジ時間 | 2,687 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ソースコード
#include <bits/stdc++.h> using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; using pi = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; template<typename T> using minQ = priority_queue<T, vector<T>, greater<T>>; #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define FOR(i,a,b) for(ll i = (ll)(a); i < (ll)(b); ++i) #define FORO(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); ++i) #define RFOR(i,a,b) for(ll i = (ll)(b) - 1; i >= (ll)(a); --i) #define RFORO(i,a,b) for(ll i = (ll)(b); i >= (ll)(a); --i) #define REP(i,n) for(ll i = 0; i < (ll)(n); ++i) #define REPO(i,n) for(ll i = 1; i <= (ll)(n); ++i) #define RREP(i,n) for(ll i = (ll)(n) - 1; i >= 0; --i) #define RREPO(i,n) for(ll i = (ll)(n); i >= 1; --i) #define SORT(a) sort(ALL(a)) #define UNIQ(a) a.erase(unique(ALL(a)), a.end()) #define SUNIQ(a) SORT(a), UNIQ(a) #define MINI(a,b) a=min(a,(b)) #define MAXI(a,b) a=max(a,(b)) #define puts(a) cout<<(a)<<endl const ll mod = 1e9 + 7; const int INF = 1e9 + 10; const ll LINF = 1000000000000000000ll; const ld eps = 1e-8; const ld PI = acosl(-1); ll Nll() { ll a; cin >> a; return a; } ld Nld() { ld a; cin >> a; return a; } int Ni() { int a; cin >> a; return a; } char Nc() { char a; cin >> a; return a; } string Ns() { string a; cin >> a; return a; } template <typename T> void O(T &&a) { puts(a); } template <typename T> void Os(const vector<T> &v) { REP(i, v.size()) cout << v[i] << " \n"[i + 1 == (ll)v.size()]; } template <typename T> void Os(vector<T> &&v) { REP(i, v.size()) cout << v[i] << " \n"[i + 1 == (ll)v.size()]; } template <typename T> void Is(vector<T> &v) { for (auto& t : v) cin >> t; } void yes(bool f = true) { puts(f ? "yes" : "no"); } void Yes(bool f = true) { puts(f ? "Yes" : "No"); } void YES(bool f = true) { puts(f ? "YES" : "NO"); } struct Edge { int from, to; Edge() {} Edge(int f, int t) : from(f), to(t) {} }; using Edges = vector<Edge>; using Graph = vector<Edges>; void solve(); int main() { ios::sync_with_stdio(false), cin.tie(0); cout << fixed << setprecision(20); solve(); } //-----------------------------------------------template------------------------------------------------------------ //-----------------------------------------------library------------------------------------------------------------- ll Pow(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = res * a % mod; a = a * a % mod; b >>= 1; } return res; } const int MAX = 3e6; ll fac[MAX + 1], ifac[MAX + 1]; ll C(ll n, ll k) { if (k < 0 || n < k) return 0; return fac[n] * ifac[k] % mod * ifac[n - k] % mod; } ll P(ll n, ll k) { if (k < 0 || n < k) return 0; return fac[n] * ifac[n - k] % mod; } ll H(ll n, ll k) { return C(n + k - 1, k); } void solve() { fac[0] = 1; REPO(i, MAX) fac[i] = fac[i - 1] * i % mod; ifac[MAX] = Pow(fac[MAX], mod - 2); RREP(i, MAX) ifac[i] = ifac[i + 1] * (i + 1) % mod; int T = Ni(); while (T--) { char c = Nc(); Nc(); ll N = Ni(); Nc(); ll K = Ni(); Nc(); if (c == 'C') { O(C(N, K)); } else if (c == 'P') { O(P(N, K)); } else { O(H(N, K)); } } }