結果
問題 |
No.2874 Gunegune Tree
|
ユーザー |
![]() |
提出日時 | 2024-09-21 15:05:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 45 ms / 2,000 ms |
コード長 | 1,561 bytes |
コンパイル時間 | 2,072 ms |
コンパイル使用メモリ | 200,892 KB |
最終ジャッジ日時 | 2025-02-24 11:16:33 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; #define ALL(v) v.begin(),v.end() #define dbg(x) cerr << #x << ": " << (x) << endl; ll modpow(ll a, ll n, ll mod) { a %= mod; ll ans = 1; while (n) { if (n & 1) ans = ans * a % mod; a = a * a % mod; n >>= 1; } return ans; } int N; int main() { cin >> N; ll mod = 998244353; vector exp(5, vector<ll>(N)), prob(5, vector<ll>(N)); vector<bitset<5>> next(5); next[0].set(0); next[0].set(1); next[1].set(0); next[1].set(1); next[1].set(2); next[2].set(1); next[2].set(2); next[2].set(3); next[3].set(2); next[3].set(3); next[3].set(4); next[4].set(3); next[4].set(4); vector<int> inv(6); for (int i = 1; i < 6; ++i) inv[i] = modpow(i, mod-2, mod); exp[1][0] = exp[2][0] = exp[3][0] = inv[5]; for (int d = 0; d < 5; ++d) prob[d][0] = inv[5]; for (int i = 1; i < N; ++i) { for (int d = 0; d < 5; ++d) { for (int to = 0; to < 5; ++to) { if (next[d].test(to)) { int grow = (1 <= to && to <= 3) * prob[d][i-1]; exp[to][i] += (exp[d][i-1] + grow) * inv[ next[d].count() ] % mod; exp[to][i] %= mod; prob[to][i] += prob[d][i-1] * inv[ next[d].count() ] % mod; prob[to][i] %= mod; } } } } ll ans = 0; for (int i = 0; i < 5; ++i) ans += exp[i][N-1]; ans %= mod; cout << ans << '\n'; }