結果
問題 | No.2874 Gunegune Tree |
ユーザー |
![]() |
提出日時 | 2024-09-07 00:08:35 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,889 ms / 2,000 ms |
コード長 | 1,588 bytes |
コンパイル時間 | 2,249 ms |
コンパイル使用メモリ | 199,952 KB |
最終ジャッジ日時 | 2025-02-24 05:02:09 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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;template<class F, class S>ostream& operator<<(ostream& os, pair<F,S>& p) {os << '(' << p.first << ',' << p.second << ')';return os;}template<class Iter>void print(Iter beg, Iter end) {for (Iter itr = beg; itr != end; ++itr) {cerr << *itr << ' ';}cerr << '\n';}ll modpow(ll x, ll n, ll mod) {x %= mod;ll res = 1;while (n > 0) {if (n&1) res = res*x%mod;x = x*x%mod;n >>= 1;}return res;}int n;ll mod = 998244353;int main() {cin >> n;ll inv5 = modpow(5, mod-2, mod);vector prob(5, vector<ll>(n+1)), exp(5, vector<ll>(n+1));for (int i = 0; i < 5; ++i) prob[i][1] = inv5;exp[0][1] = exp[4][1] = 0;exp[1][1] = exp[2][1] = exp[3][1] = inv5;vector<int> l{ 0, 0, 1, 2, 3 };vector<int> r{ 2, 3, 4, 5, 5 };int dy[] = {0, 1, 1, 1, 0};for (int i = 2; i <= n; ++i) {for (int j = 0; j < 5; ++j) {for (int k = l[j]; k < r[j]; ++k) {ll p = modpow(r[j]-l[j], mod-2, mod);// probprob[k][i] += prob[j][i-1] * p % mod;prob[k][i] %= mod;// expexp[k][i] += (exp[j][i-1] * p % mod + dy[k] * p % mod * prob[j][i-1]) % mod;exp[k][i] %= mod;}}}ll ans = 0;for (int i = 0; i < 5; ++i) ans = (exp[i][n] + ans) % mod;cout << ans << '\n';}