結果
問題 | No.1547 [Cherry 2nd Tune *] 偶然の勝利の確率 |
ユーザー | Kude |
提出日時 | 2021-06-11 23:41:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 98 ms / 2,000 ms |
コード長 | 2,264 bytes |
コンパイル時間 | 4,694 ms |
コンパイル使用メモリ | 270,200 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-08 20:16:45 |
合計ジャッジ時間 | 7,011 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 5 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 18 ms
5,376 KB |
testcase_14 | AC | 13 ms
5,376 KB |
testcase_15 | AC | 6 ms
5,376 KB |
testcase_16 | AC | 9 ms
5,376 KB |
testcase_17 | AC | 9 ms
5,376 KB |
testcase_18 | AC | 9 ms
5,376 KB |
testcase_19 | AC | 4 ms
5,376 KB |
testcase_20 | AC | 56 ms
5,376 KB |
testcase_21 | AC | 6 ms
5,376 KB |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 97 ms
5,376 KB |
testcase_24 | AC | 98 ms
5,376 KB |
testcase_25 | AC | 97 ms
5,376 KB |
testcase_26 | AC | 97 ms
5,376 KB |
testcase_27 | AC | 98 ms
5,376 KB |
testcase_28 | AC | 98 ms
5,376 KB |
testcase_29 | AC | 97 ms
5,376 KB |
testcase_30 | AC | 98 ms
5,376 KB |
testcase_31 | AC | 97 ms
5,376 KB |
testcase_32 | AC | 98 ms
5,376 KB |
testcase_33 | AC | 98 ms
5,376 KB |
testcase_34 | AC | 9 ms
5,376 KB |
testcase_35 | AC | 10 ms
5,376 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; #define rep(i,n)for (int i = 0; i < int(n); ++i) #define rrep(i,n)for (int i = int(n)-1; i >= 0; --i) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template<class T> void chmax(T& a, const T& b) {a = max(a, b);} template<class T> void chmin(T& a, const T& b) {a = min(a, b);} using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; using mint = modint998244353; struct mat: std::vector<std::vector<mint>> { mat(int n=0): std::vector<std::vector<mint>>::vector(n, vector<mint>(n)) {} friend mat operator*(const mat& lhs, const mat& rhs) { const int n = lhs.size(); mat ret(n); for(int i = 0; i < n; i++) for(int k = 0; k < n; k++) for(int j = 0; j < n; j++) { ret[i][j] += lhs[i][k] * rhs[k][j]; } return ret; } mat& operator*=(const mat& rhs) { return (*this) = (*this) * rhs; } mat pow(unsigned long long n) { mat A = *this; mat res = mat::I(A.size()); for(; n; n >>= 1) { if (n & 1) res *= A; A *= A; } return res; } static mat I(int n) { mat ret(n); for(int i = 0; i < n; i++) ret[i][i] = mint::raw(1); return ret; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int ma, na, s, mb, nb, t; cin >> ma >> na >> s >> mb >> nb >> t; mint p = mint(ma) / na, q = mint(mb) / nb; mat A(s + t + 1), B(s + t + 1); A[0][0] = 1; A[s+t][s+t] = 1; for(int i = 1; i < s + t; i++) { mint now = 1; for(int j = i; j < s + t; j++) { A[i][j] = now * (1 - p); now *= p; } A[i][s + t] = now; } B[0][0] = 1; B[s+t][s+t] = 1; for(int i = 1; i < s + t; i++) { mint now = 1; for(int j = i; j > 0; j--) { B[i][j] = now * (1 - q); now *= q; } B[i][0] = now; } ll k; cin >> k; mat X = (A * B).pow(k); mint ans1 = X[t][s + t], ans2 = X[t][0]; cout << ans1.val() << '\n' << ans2.val() << '\n'; }