結果
問題 | No.2877 Gunegune Hyperion |
ユーザー | FUN_Morikubo |
提出日時 | 2024-09-06 22:08:35 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,940 KB |
testcase_02 | AC | 4 ms
6,940 KB |
testcase_03 | AC | 391 ms
15,068 KB |
testcase_04 | AC | 417 ms
15,240 KB |
testcase_05 | AC | 940 ms
27,064 KB |
testcase_06 | AC | 955 ms
26,912 KB |
testcase_07 | AC | 979 ms
27,160 KB |
testcase_08 | AC | 934 ms
26,988 KB |
testcase_09 | AC | 839 ms
26,980 KB |
testcase_10 | AC | 1,717 ms
50,600 KB |
testcase_11 | AC | 811 ms
26,968 KB |
testcase_12 | AC | 175 ms
9,236 KB |
testcase_13 | AC | 390 ms
15,208 KB |
testcase_14 | AC | 190 ms
9,248 KB |
testcase_15 | AC | 838 ms
26,700 KB |
testcase_16 | AC | 1,823 ms
50,584 KB |
testcase_17 | AC | 1,778 ms
50,364 KB |
testcase_18 | AC | 378 ms
15,076 KB |
testcase_19 | AC | 458 ms
15,260 KB |
testcase_20 | AC | 25 ms
6,940 KB |
testcase_21 | AC | 1,723 ms
50,492 KB |
testcase_22 | AC | 904 ms
27,104 KB |
testcase_23 | AC | 1,824 ms
50,356 KB |
testcase_24 | AC | 1,725 ms
50,604 KB |
testcase_25 | AC | 1,891 ms
50,856 KB |
testcase_26 | AC | 424 ms
15,168 KB |
testcase_27 | AC | 930 ms
26,760 KB |
testcase_28 | AC | 1,859 ms
50,984 KB |
testcase_29 | AC | 1,849 ms
50,728 KB |
testcase_30 | AC | 1,847 ms
50,856 KB |
testcase_31 | AC | 1,867 ms
50,724 KB |
testcase_32 | AC | 1,851 ms
50,852 KB |
ソースコード
#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 vector template <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_DEBUG struct 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(); } }