結果

問題 No.2199 lower_bound and upper_bound
ユーザー AngrySadEightAngrySadEight
提出日時 2022-10-26 00:39:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 1,380 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 74,428 KB
実行使用メモリ 8,016 KB
最終ジャッジ日時 2023-09-16 21:03:57
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 225 ms
7,788 KB
testcase_01 AC 228 ms
7,752 KB
testcase_02 AC 221 ms
7,708 KB
testcase_03 AC 227 ms
7,832 KB
testcase_04 AC 226 ms
7,704 KB
testcase_05 AC 229 ms
7,688 KB
testcase_06 AC 226 ms
7,888 KB
testcase_07 AC 226 ms
7,780 KB
testcase_08 AC 228 ms
7,788 KB
testcase_09 AC 228 ms
7,720 KB
testcase_10 AC 227 ms
7,700 KB
testcase_11 AC 225 ms
7,832 KB
testcase_12 AC 226 ms
7,776 KB
testcase_13 AC 229 ms
8,016 KB
testcase_14 AC 222 ms
7,780 KB
testcase_15 AC 226 ms
7,688 KB
testcase_16 AC 228 ms
7,760 KB
testcase_17 AC 229 ms
7,772 KB
testcase_18 AC 217 ms
7,788 KB
testcase_19 AC 222 ms
7,752 KB
testcase_20 AC 219 ms
7,716 KB
testcase_21 AC 226 ms
7,832 KB
testcase_22 AC 219 ms
7,720 KB
testcase_23 AC 223 ms
7,664 KB
testcase_24 AC 215 ms
7,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll my_pow(ll x, ll n, ll mod){
    ll ret;
    if (n == 0){
        ret = 1;
    }
    else if (n % 2 == 0){
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    else{
        ret = (x * (my_pow((x * x) % mod, n / 2, mod))) % mod;
    }
    return ret;
}

ll inv(ll x, ll mod){
    return my_pow(x, mod - 2, mod);
}

ll comb(ll n, ll r, vector<ll> &fact, vector<ll> &fact_inv, ll mod){
    //nCr
    ll ret;
    ret = (fact[n] * fact_inv[n - r]) % mod;
    ret = (ret * fact_inv[r]) % mod;
    return ret;
}

int main(){
    ll N,L,U;
    cin >> N >> L >> U;
    
    ll mod = 998244353;

    vector<ll> fact(300003);
    fact[0] = 1;
    for (ll i = 0; i < 300002; i++){
        fact[i + 1] = (fact[i] * (i + 1)) % mod;
    }
    vector<ll> fact_inv(300003);
    for (ll i = 0; i < 300003; i++){
        fact_inv[i] = inv(fact[i], mod);
    }

    ll ans = 0;
    for (ll i = L + N; i <= U + N; i++){
        ll x1 = N - 1;
        ll y1 = i;
        ll comb1 = comb(x1 + y1, y1, fact, fact_inv, mod);
        ans = (ans + comb1) % mod;
        
        ll x2 = x1 + U + 2;
        ll y2 = y1 - U - 2;

        if (y2 >= 0){
            ll comb2 = comb(x2 + y2, y2, fact, fact_inv, mod);
            ans = (ans + mod - comb2) % mod; 
        }
    }
    cout << ans << endl;

    return 0;
}
0