結果

問題 No.2199 lower_bound and upper_bound
ユーザー Caiiiiiiii
提出日時 2025-01-12 17:19:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 2,093 ms
コンパイル使用メモリ 191,188 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2025-01-12 17:19:12
合計ジャッジ時間 3,357 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   34 |   scanf("%d%d%d", &n, &l, &u);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>

using LL = long long;

const int N = 3e5 + 7;
const int MOD = 998244353;

int n, l, u, fac[N], ifc[N];

int pow(int x, int y) {
  int ret = 1;
  while(y) {
    if(y & 1)
      ret = 1LL * ret * x % MOD;
    x = 1LL * x * x % MOD;
    y >>= 1;
  }
  return ret;
}

int com(int x, int y) {
  return x >= y && y >= 0 ? 1LL * fac[x] * ifc[y] % MOD * ifc[x - y] % MOD : 0;
}

int main() {

  fac[0] = 1;
  for(int i = 1; i < N; ++i) 
    fac[i] = 1LL * fac[i - 1] * i % MOD;
  ifc[N - 1] = pow(fac[N - 1], MOD - 2);
  for(int i = N - 2; i >= 0; --i) 
    ifc[i] = 1LL * ifc[i + 1] * (i + 1) % MOD;

  scanf("%d%d%d", &n, &l, &u);

  printf("%lld\n", (2LL * MOD + com(2 * n + u, n + u) - com(2 * n + l - 1, n + l - 1) -
		    com(2 * n + u, n - 2) + com(2 * n + l - 1, n + l - u - 3)) % MOD);
  
  return 0;
}
0