結果

問題 No.2572 Midori on the grid
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-12-02 15:43:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 215 ms / 5,000 ms
コード長 2,198 bytes
コンパイル時間 6,030 ms
コンパイル使用メモリ 265,224 KB
実行使用メモリ 26,828 KB
最終ジャッジ日時 2023-12-02 15:44:06
合計ジャッジ時間 8,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 215 ms
26,828 KB
testcase_01 AC 115 ms
26,828 KB
testcase_02 AC 177 ms
26,828 KB
testcase_03 AC 164 ms
26,828 KB
testcase_04 AC 98 ms
26,828 KB
testcase_05 AC 176 ms
26,828 KB
testcase_06 AC 36 ms
26,824 KB
testcase_07 AC 37 ms
26,824 KB
testcase_08 AC 36 ms
26,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast {
  Fast() {
    std::cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(10);
  }
} fast;

#define all(a) (a).begin(), (a).end()
#define contains(a, x) ((a).find(x) != (a).end())
#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define YN(b) cout << ((b) ? "YES" : "NO") << "\n";
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define yn(b) cout << ((b) ? "yes" : "no") << "\n";

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  }
  return os;
}

using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vm>;
inline ostream& operator<<(ostream& os, const mint P) { return os << P.val(); };

template <typename mint>
class Factorial {
 public:
  Factorial(int max) : n(max) {
    f = std::vector<mint>(n + 1);
    finv = std::vector<mint>(n + 1);
    f[0] = 1;
    for (int i = 1; i <= n; i++) f[i] = f[i - 1] * i;
    finv[n] = f[n].inv();
    for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * i;
  }
  mint fact(int k) const {
    assert(0 <= k && k <= n);
    return f[k];
  }
  mint fact_inv(int k) const {
    assert(0 <= k && k <= n);
    return finv[k];
  }
  mint binom(int k, int r) const {
    assert(0 <= k && k <= n);
    if (r < 0 || r > k) return 0;
    return f[k] * finv[r] * finv[k - r];
  }
  mint inv(int k) const {
    assert(0 < k && k <= n);
    return finv[k] * f[k - 1];
  }

 private:
  int n;
  std::vector<mint> f, finv;
};

void solve() {
  int h, w, q;
  cin >> h >> w >> q;

  Factorial<mint> fact(3000000);

  while (q--) {
    int t;
    cin >> t;
    mint ans = fact.binom(h + w, h) - fact.binom(h + w, h + t);
    if ((ll)t * (h + t - w) < 0) ans = 0;
    cout << ans << "\n";
  }
}

int main() {
  int t = 1;
  // cin >> t;
  while (t--) solve();
}
0