結果

問題 No.1785 Inequality Signs
ユーザー karinohitokarinohito
提出日時 2021-12-14 15:03:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,372 bytes
コンパイル時間 1,524 ms
コンパイル使用メモリ 169,400 KB
実行使用メモリ 814,584 KB
最終ジャッジ日時 2023-10-01 00:07:20
合計ジャッジ時間 5,077 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 26 ms
6,184 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

vector<ll> fact, factinv, inv;
ll mod = 1e9 + 7;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	if (n < k) return 0;
	return fact.at(n) * (factinv.at(k) * factinv.at(n - k) % mod) % mod;
}
ll inva(ll N) {
    ll a = N, b = mod, c = 1, d = 0;
    while (b > 0) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        c -= t * d;
        swap(c, d);

    }
    c %= mod;
    if (c < 0)c += mod;
    return c;

}

int main() {
   ll N,K;
   cin>>N>>K;
   prenCkModp(K+N+3);
   ll an=0;
   ll p=1;
   rep(i,N){
       p*=(K+N-1-i);
       p%=mod;
       p*=inv[i+1];
       p%=mod;
   }
   rep(k,min(N,K)){
       an+=p;
       an%=mod;
       //cout<<p<<endl;
       p*=(K-1-k);
       p%=mod;
       p*=inva(K+N-1-k);
       p%=mod;
       p*=inva(k+1);
       p%=mod;
       p*=(N-1-k);
       p%=mod;
       
   }
   cout<<an<<endl;
}
0