結果
問題 | No.1191 数え上げを愛したい(数列編) |
ユーザー | toma |
提出日時 | 2020-08-22 17:26:08 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,182 bytes |
コンパイル時間 | 2,002 ms |
コンパイル使用メモリ | 205,444 KB |
実行使用メモリ | 8,192 KB |
最終ジャッジ日時 | 2024-10-15 11:17:41 |
合計ジャッジ時間 | 2,988 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | AC | 9 ms
8,064 KB |
testcase_16 | AC | 9 ms
8,132 KB |
testcase_17 | AC | 9 ms
8,064 KB |
testcase_18 | AC | 10 ms
8,064 KB |
testcase_19 | AC | 8 ms
8,192 KB |
testcase_20 | AC | 10 ms
8,064 KB |
testcase_21 | AC | 8 ms
8,064 KB |
testcase_22 | WA | - |
testcase_23 | AC | 9 ms
8,192 KB |
testcase_24 | AC | 8 ms
8,064 KB |
testcase_25 | AC | 8 ms
8,064 KB |
ソースコード
#include"bits/stdc++.h" using namespace std; #define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) REP((i),0,(n)) using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using tp3 = tuple<int, int, int>; using Mat = vector<vector<ll>>; constexpr int INF = 1 << 28; constexpr ll INFL = 1ll << 60; constexpr int dh[4] = { 0,1,0,-1 }; constexpr int dw[4] = { -1,0,1,0 }; bool isin(const int H, const int W, const int h, const int w) { return 0 <= h && h < H && 0 <= w && w < W; } struct ModInt { static const ll MOD = 998244353; // constructors etc ModInt() :num(1ll) {} ModInt(ll num_) :num(num_%MOD) {} ModInt(const ModInt& modint) :num(modint.num%MOD) {} ll get()const { return num; } // operator etc // operator ll() const { return num; } // ll operator*() { return num; } ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; } ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; } ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; } ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; } ModInt pow(const ModInt& r)const { ll res = 1; ll x = num; ll n = r.num; while (n > 0) { if (n & 1)res = (res*x) % MOD; x = (x*x) % MOD; n >>= 1; } return res; } ModInt inv()const { return this->pow(MOD - 2); } ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; } ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; } ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; } ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; } ModInt operator+(const ll& r)const { return *this + ModInt(r); } ModInt operator-(const ll& r)const { return *this - ModInt(r); } ModInt operator*(const ll& r)const { return *this * ModInt(r); } ModInt operator/(const ll& r)const { return *this / ModInt(r); } private: ll num; }; ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; } struct Comb { static constexpr ll LIM = 310000; static vector<ModInt> fact, inv; static void init() { fact.resize(LIM, 1); inv.resize(LIM, 1); REP(i, 1, LIM)fact[i] = fact[i - 1] * i; inv[LIM - 1] = fact[LIM - 1].inv(); for (ll i = LIM - 2; i > 0; i--)inv[i] = inv[i + 1] * (i + 1); } static ll comb(ll n, ll k) { if (n < k)return 0ll; return (fact[n] * inv[k] * inv[n - k]).get(); } }; vector<ModInt> Comb::fact; vector<ModInt> Comb::inv; // ============ template finished ============ int main() { ll N, M, A, B; cin >> N >> M >> A >> B; Comb::init(); ll ball = B - A * (N - 1); ll board = N - 1; if (ball < 0) { cout << 0 << endl; return 0; } ModInt res(0); const int LIM = B - A * (N - 1); rep(alpha, LIM + 1) { auto tres = Comb::fact[N] * Comb::comb(alpha + N, alpha); res += tres; } cout << res << endl; return 0; }