結果
問題 | No.2199 lower_bound and upper_bound |
ユーザー |
👑 ![]() |
提出日時 | 2022-10-26 00:39:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 250 ms / 2,000 ms |
コード長 | 1,380 bytes |
コンパイル時間 | 660 ms |
コンパイル使用メモリ | 74,412 KB |
最終ジャッジ日時 | 2025-02-08 12:42:28 |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#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){//nCrll 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;}