結果

問題 No.1785 Inequality Signs
ユーザー karinohitokarinohito
提出日時 2021-12-14 15:04:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,370 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 168,588 KB
実行使用メモリ 7,872 KB
最終ジャッジ日時 2023-10-01 00:07:39
合計ジャッジ時間 6,490 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 19 ms
4,376 KB
testcase_02 AC 106 ms
6,344 KB
testcase_03 AC 131 ms
7,632 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 60 ms
4,760 KB
testcase_06 AC 130 ms
6,868 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 118 ms
6,868 KB
testcase_09 AC 23 ms
4,376 KB
testcase_10 AC 85 ms
5,812 KB
testcase_11 AC 26 ms
4,380 KB
testcase_12 AC 46 ms
4,696 KB
testcase_13 AC 20 ms
4,376 KB
testcase_14 AC 66 ms
5,020 KB
testcase_15 AC 53 ms
4,892 KB
testcase_16 AC 40 ms
4,376 KB
testcase_17 AC 85 ms
5,848 KB
testcase_18 AC 87 ms
5,892 KB
testcase_19 AC 70 ms
5,288 KB
testcase_20 AC 75 ms
5,548 KB
testcase_21 AC 69 ms
5,352 KB
testcase_22 AC 24 ms
4,376 KB
testcase_23 AC 38 ms
4,380 KB
testcase_24 AC 146 ms
7,472 KB
testcase_25 AC 56 ms
4,880 KB
testcase_26 AC 51 ms
4,620 KB
testcase_27 AC 125 ms
7,796 KB
testcase_28 AC 125 ms
7,660 KB
testcase_29 AC 126 ms
7,792 KB
testcase_30 AC 125 ms
7,792 KB
testcase_31 AC 125 ms
7,872 KB
testcase_32 AC 126 ms
7,748 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 6 ms
4,376 KB
testcase_36 AC 71 ms
6,944 KB
testcase_37 AC 30 ms
7,488 KB
testcase_38 AC 28 ms
6,752 KB
testcase_39 AC 16 ms
4,380 KB
testcase_40 AC 25 ms
4,620 KB
testcase_41 AC 35 ms
5,364 KB
testcase_42 AC 80 ms
7,448 KB
testcase_43 AC 114 ms
7,544 KB
testcase_44 AC 93 ms
6,676 KB
testcase_45 AC 16 ms
4,492 KB
testcase_46 AC 29 ms
6,684 KB
testcase_47 AC 21 ms
5,228 KB
testcase_48 AC 39 ms
5,816 KB
testcase_49 AC 3 ms
4,380 KB
testcase_50 AC 92 ms
6,792 KB
testcase_51 AC 10 ms
4,380 KB
testcase_52 AC 7 ms
4,380 KB
testcase_53 AC 14 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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(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