結果
問題 |
No.2874 Gunegune Tree
|
ユーザー |
![]() |
提出日時 | 2024-09-06 22:45:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 1,188 bytes |
コンパイル時間 | 1,843 ms |
コンパイル使用メモリ | 194,076 KB |
最終ジャッジ日時 | 2025-02-24 04:40:52 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define pb emplace_back #define mp make_pair using ll = long long; using pii = pair<int,int>; constexpr int mod = 998244353; constexpr int inf = 0x3f3f3f3f; constexpr int N = 2e5 + 10; ll pow_mod(ll x, ll p){ ll s = 1; while(p){ if(p & 1) s = s * x % mod; x = x * x % mod; p >>= 1; } return s; } void add(int &x, int y){ x += y; if(x >= mod) x -= mod; } ll P[10]; int n, dp[N][5], cnt[5]; void _main(){ int n; for(int i=2; i<=5; ++i) P[i] = pow_mod(i, mod - 2); for(int i=0; i<5; ++i){ dp[1][i] = P[5]; } for(int i=0; i<5; ++i){ cnt[i] = 0; for(int j=0; j<5; ++j){ if(abs(i - j) <= 1){ ++cnt[i]; } } } cin >> n; int ans = 1ll * 3 * P[5] % mod; for(int i=1; i<n; ++i){ for(int j=0; j<5; ++j){ for(int k=0; k<5; ++k){ if(abs(j - k) <= 1){ int tmp = 1ll * dp[i][k] * P[cnt[k]] % mod; add(dp[i+1][j], tmp); if(j > 0 && j < 4){ add(ans, tmp); } } } } } cout << ans << '\n'; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); _main(); return 0; }