結果
| 問題 |
No.2874 Gunegune Tree
|
| コンテスト | |
| ユーザー |
n0ma_ru
|
| 提出日時 | 2024-09-07 00:13:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 228 ms / 2,000 ms |
| コード長 | 1,665 bytes |
| コンパイル時間 | 2,179 ms |
| コンパイル使用メモリ | 200,648 KB |
| 最終ジャッジ日時 | 2025-02-24 05:02:30 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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};
vector<ll> mp;
for (int i = 0; i <= 5; ++i) mp.push_back(modpow(i, mod-2, mod));
for (int i = 2; i <= n; ++i) {
for (int j = 0; j < 5; ++j) {
for (int k = l[j]; k < r[j]; ++k) {
// prob
prob[k][i] += prob[j][i-1] * mp[r[j]-l[j]] % mod;
prob[k][i] %= mod;
// exp
exp[k][i] += (exp[j][i-1] * mp[r[j]-l[j]] % mod + dy[k] * mp[r[j]-l[j]] % mod * prob[j][i-1] % mod) % mod;
exp[k][i] %= mod;
}
}
}
ll ans = 0;
for (int i = 0; i < 5; ++i) ans = (exp[i][n] + ans) % mod;
cout << ans << '\n';
}
n0ma_ru