結果
問題 | No.2685 Cell Proliferation (Easy) |
ユーザー |
![]() |
提出日時 | 2024-04-26 17:27:28 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,904 bytes |
コンパイル時間 | 415 ms |
コンパイル使用メモリ | 46,464 KB |
実行使用メモリ | 7,160 KB |
最終ジャッジ日時 | 2024-11-14 07:00:56 |
合計ジャッジ時間 | 1,606 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
/* -*- coding: utf-8 -*- * * 2685.cc: No.2685 Cell Proliferation (Easy) - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_T = 1000; const int MOD = 998244353; /* typedef */ template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; } MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; } explicit operator int() const { return v; } MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } bool operator==(const MI m) const { return v == m.v; } bool operator!=(const MI m) const { return v != m.v; } MI pow(int n) const { // a^n % MOD MI pm = 1, a = *this; while (n > 0) { if (n & 1) pm *= a; a *= a; n >>= 1; } return pm; } MI inv() const { return pow(MOD - 2); } MI operator/(const MI m) const { return *this * m.inv(); } MI &operator/=(const MI m) { return (*this = *this / m); } }; typedef MI<MOD> mi; /* global variables */ mi eqs[MAX_T + 1], dp[MAX_T + 1][MAX_T + 1]; /* subroutines */ /* main */ int main() { int p1, p2, q1, q2, t; scanf("%d%d%d%d%d", &p1, &p2, &q1, &q2, &t); mi p = mi(p1) / p2, q = mi(q1) / q2; eqs[0] = 1; for (int i = 1; i <= t; i++) eqs[i] = eqs[i - 1] * q; dp[0][0] = 1; for (int i = 1; i <= t; i++) { for (int j = 0; j <= t; j++) dp[i][0] += dp[i - 1][j] * p; for (int j = 1; j <= t; j++) dp[i][j] = dp[i - 1][j - 1] * eqs[j]; } mi sum = 0; for (int j = 0; j <= t; j++) sum += dp[t][j]; printf("%d\n", (int)sum); return 0; }