結果
問題 | No.2877 Gunegune Hyperion |
ユーザー |
|
提出日時 | 2024-09-06 22:08:35 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,891 ms / 6,000 ms |
コード長 | 5,957 bytes |
コンパイル時間 | 5,841 ms |
コンパイル使用メモリ | 325,348 KB |
実行使用メモリ | 50,984 KB |
最終ジャッジ日時 | 2024-09-06 22:09:58 |
合計ジャッジ時間 | 39,453 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#if 1// clang-format off#include <bits/stdc++.h>#include <atcoder/all>using namespace atcoder;using mint93 = modint998244353;using mint17 = modint1000000007;using mint = modint;using vm93 = std::vector<mint93>;using vvm93 = std::vector<vm93>;using vm17 = std::vector<mint17>;using vvm17 = std::vector<vm17>;using namespace std;using uint = unsigned int;using ll = long long;using ull = unsigned long long;using lf = long double;using pll = pair<ll, ll>;#define vec vectortemplate <class T> using v = vector<T>;template <class T> using vv = v<v<T>>;template <class T> using vvv = v<vv<T>>;using vl = v<ll>;using vvl = vv<ll>;using vvvl = vvv<ll>;using vpl = v<pll>;using vs = v<string>;using vb = v<bool>;using vvb = v<vb>;using vvvb = v<vvb>;template<class T> using PQ = priority_queue<T, v<T>, greater<T>>;constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)#define rep(i, N) for (ll i = 0; i < (ll)(N); i++)#define rep1(i, N) for (ll i = 1; i <= (ll)(N); i++)#define rrep(i, N) for (ll i = N - 1; i >= 0; i--)#define rrep1(i, N) for (ll i = N; i > 0; i--)#define fore(i, a) for (auto &i : a)#define fs first#define sc second#define eb emplace_back#define pb push_back#define all(x) (x).begin(), (x).end()#define rall(x) (x).rbegin(), (x).rend()#define UNIQUE(x) (x).erase(unique((x).begin(), (x).end()), (x).end());#define YES(x) cout << ((x) ? "YES\n" : "NO\n");#define Yes(x) cout << ((x) ? "Yes\n" : "No\n");#define yes(x) cout << ((x) ? "yes\n" : "no\n");template <class T, class U> void chmin(T &t, const U &u) { if (t > u) t = u; }template <class T, class U> void chmax(T &t, const U &u) { if (t < u) t = u; }template <class T> T min(const v<T> &lis) { return *min_element(all(lis)); }template <class T> T max(v<T> &lis) { return *max_element(all(lis)); }const int inf = (1 << 30);const ll infl = (1LL << 60);const ll mod93 = 998244353;const ll mod17 = 1000000007;int popcnt(uint x) { return __builtin_popcount(x); }int popcnt(ull x) { return __builtin_popcountll(x); }// 桁数int bsr(uint x) { return 31 - __builtin_clz(x); }int bsr(ull x) { return 63 - __builtin_clzll(x); }// 2で割れる回数int bsf(uint x) { return __builtin_ctz(x); }int bsf(ull x) { return __builtin_ctzll(x); }template <class T, class S> istream &operator>>(istream &is, pair<T, S> &x) { return is >> x.first >> x.second; }template <class T, class S> ostream &operator<<(ostream &os, const pair<T, S> &x) { return os << x.first << " " << x.second; }template <class T> istream &operator>>(istream &is, vector<T> &x) { for (auto &y : x) is >> y; return is; }template <class T> ostream &operator<<(ostream &os, const vector<T> &x) {for (size_t i = 0, size = x.size(); i < size; i++)os << x[i] << (i == size - 1 ? "" : " ");return os;}ll rand_int(ll l, ll r) { // [l, r]static random_device rd;static mt19937 gen(rd());return uniform_int_distribution<ll>(l, r)(gen);}template <long long MOD = 998244353> struct binomial {long long n;std::vector<atcoder::static_modint<MOD>> fact, ifact;binomial(long long n) : n(n), fact(n + 1), ifact(n + 1) {fact[0] = 1;for (int i = 1; i <= n; i++)fact[i] = fact[i - 1] * i;ifact[n] = fact[n].inv();for (int i = n; i > 0; i--)ifact[i - 1] = ifact[i] * i;}atcoder::static_modint<MOD> operator()(int n, int k) {if (k < 0 || k > n) return 0;return fact[n] * ifact[k] * ifact[n - k];}};// #include <boost/multiprecision/cpp_int.hpp>// using cpp_int = boost::multiprecision::cpp_int;// clang-format on#endif// #define _GLIBCXX_DEBUGstruct S {array<array<vm93, 3>, 3> A;};void add(vm93 &a, vm93 &b) {if (a.size() < b.size()) swap(a, b);rep(i, b.size()) a[i] += b[i];}S e() {S ret;rep(i, 3) {rep(j, 3) {ret.A[i][j] = vm93(1);if (i == j) ret.A[i][j][0] = 1;}}return ret;}S op(S a, S b) {S ret;rep(now, 3) {rep(mid, 3) {rep(to, 3) {vm93 tmp = convolution(a.A[now][mid], b.A[mid][to]);add(ret.A[now][to], tmp);while (ret.A[now][to].size() > 0 && ret.A[now][to].back() == 0)ret.A[now][to].pop_back();}}}return ret;}S one() {S ret;mint93 two = mint93(2).inv();mint93 th = mint93(3).inv();ret.A = array<array<vm93, 3>, 3>{array<vm93, 3>{vm93{0, th}, {0, 2*th}, {}},array<vm93, 3>{vm93{0, th}, {0, th}, {th, 0}},array<vm93, 3>{ vm93{}, {0, two}, {two, 0}}};return ret;}void print(S a) {rep(i, 3) {rep(j, 3) {cout << "{";ll sz = a.A[i][j].size();rep(k, sz) {if (k > 0) cout << " ";cout << a.A[i][j][k].val();}cout << "}";}cout << "\n";}}S doubling(ll N) {S ret = e(), cur = one();while (N) {if (N & 1) ret = op(ret, cur);cur = op(cur, cur);N >>= 1;}return ret;}struct Solver {void solve() {ll N, H;cin >> N >> H;S res = doubling(N - 1);// print(res);mint93 ans_top = 0, ans_bot = 0;rep(i, 3) {mint93 tmp_top = 0, tmp_bot = 0;rep(j, 3) {ll sz = res.A[i][j].size();rep(k, sz) { tmp_bot += res.A[i][j][k]; }FOR(k, H, sz) { tmp_top += res.A[i][j][k]; }if (i != 2 && H - 1 < sz) {tmp_top += res.A[i][j][H - 1];}}if (i != 0) tmp_top *= 2, tmp_bot *= 2;ans_top += tmp_top;ans_bot += tmp_bot;// cout << i << " " << tmp_top.val() << " " << tmp_bot.val() << "\n";}mint93 ans = ans_top / ans_bot;// cout << ans_top.val() << " " << ans_bot.val() << "\n";cout << ans.val() << "\n";}};int main() {cin.tie(nullptr);ios::sync_with_stdio(false);cout << fixed << setprecision(20);ll t = 1;// cin >> t;while (t--) {Solver solver;solver.solve();}}