結果
| 問題 |
No.117 組み合わせの数
|
| コンテスト | |
| ユーザー |
白狐
|
| 提出日時 | 2019-08-06 16:33:26 |
| 言語 | C++17(clang) (17.0.6 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,523 bytes |
| コンパイル時間 | 1,180 ms |
| コンパイル使用メモリ | 142,588 KB |
| 実行使用メモリ | 35,200 KB |
| 最終ジャッジ日時 | 2024-11-30 14:28:03 |
| 合計ジャッジ時間 | 2,056 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | WA * 1 |
ソースコード
/*
∧_∧ やあ
(´・ω・`) / ようこそ、バーボンハウスへ。
/∇y:::::\ [ ̄] このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
|:⊃:|:::::| |──|
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| うん、「また」なんだ。済まない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄| ̄ 仏の顔もって言うしね、謝って許してもらおうとも思っていない。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄/|
∇ ∇ ∇ ∇ /./| でも、この提出を見たとき、君は、きっと言葉では言い表せない
┴ ┴ ┴ ┴ / / | 「ときめき」みたいなものを感じてくれたと思う。
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|/ | 殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
 ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ | そう思って、この提出を投げたんだ。
(⊆⊇) (⊆⊇) (⊆⊇) |
|| || || | じゃあ、判定を聞こうか。
./|\ /|\ /|\
*/
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};
lint gcd(lint a, lint b) {
lint r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
lint lcm(lint a, lint b) {
return (a / gcd(a, b)) * b;
}
lint power(lint x, lint n, lint mod = MOD) {
lint ret = 1;
while(n > 0) {
if(n & 1){
(ret *= x) %= mod;
}
(x *= x) %= mod;
n >>= 1;
}
return ret;
}
vector<lint> make_power(int n, lint base){
lint num = 1;
vector<lint> ret;
for (int i=0; i<=n; ++i){
ret.push_back(num);
num *= base;
}
return ret;
}
template<typename Int, Int MOD>
struct comb_util {
int sz;
vector<Int> mfact, minv_fact;
comb_util(int N) : sz(N + 1), mfact(sz), minv_fact(sz) {
mfact[0] = 1;
for (int i = 1; i <= sz; i++) mfact[i] = mfact[i - 1] * i % MOD;
minv_fact[sz] = inv(mfact[sz]);
for (int i = sz - 1; i >= 0; i--) minv_fact[i] = minv_fact[i + 1] * (i + 1) % MOD;
}
// res = first * p^second
pair<Int, Int> fact_willson(Int n) const {
Int e = 0;
if (n <= sz) return std::make_pair(mfact[n], 0);
Int res;
tie(res, e) = fact_willson(n / MOD);
e += n / MOD;
if ((n / MOD) % 2 != 0) res = MOD - res;
return make_pair(res * mfact[n % MOD] % MOD, e);
}
// find n!
Int fact(Int n) const { return mfact[n]; }
// find n ** -1
Int inv(Int n) const {
return pow(n, MOD - 2);
}
// find n ** a
Int pow(Int n, Int a) const {
Int res = 1, exp = n;
for(; a; a /= 2) {
if (a & 1) res = res * exp % MOD;
exp = exp * exp % MOD;
}
return res;
}
// find nPr
Int perm(Int n, Int r) {
if (r < 0 || n < r) return 0;
else return mfact[n] * minv_fact[n - r] % MOD;
}
Int binom_lucus(Int n, Int r) const {
if (n < 0 || r < 0 || n < r) return 0;
assert(n <= sz);
if (n >= MOD) return binom(n % MOD, r % MOD) * binom(n / MOD, r / MOD);
else return r > n ? 0 : mfact[n] * minv_fact[n - r] * minv_fact[r];
}
// find nCr
Int binom(Int n, Int r) const {
if (n < 0 || r < 0 || n < r) return 0;
return mfact[n] * minv_fact[r] % MOD * minv_fact[n - r] % MOD;
}
// find nHr
Int homo(Int n, Int r) const {
if (n < 0 || r < 0) return 0;
return r == 0 ? 1 : binom(n + r - 1, r);
}
};
using comb = comb_util<long long, 1000000007>;
int main(){
int T;
comb cm(2000010);
cin >> T;
vector<int> ans;
REP(i, T){
char c;
int N, K;
scanf("%c(%d,%d)\r\n",&c,&N,&K);
if (c=='C'){
ans.push_back(cm.binom(N, K));
}
else if (c=='P'){
ans.push_back(cm.perm(N, K));
}
else if (c=='H'){
ans.push_back(cm.homo(N, K));
}
}
REP(i, T){
cout << ans[i] << endl;
}
}
白狐