結果

問題 No.3080 Colonies on Line
ユーザー Kude
提出日時 2025-03-28 23:43:15
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,333 ms / 6,500 ms
コード長 2,102 bytes
コンパイル時間 4,244 ms
コンパイル使用メモリ 310,224 KB
実行使用メモリ 10,844 KB
最終ジャッジ日時 2025-03-28 23:43:38
合計ジャッジ時間 22,095 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

// https://web.archive.org/web/20220813130855/https://opt-cp.com/orbit-counting-lemma/
// 有理式 p(x) / q(x) で表される形式的冪級数の x^n の係数を計算
template<class T>
struct bostan_mori {
  vector<T> p, q;
  bostan_mori(vector<T> &_p, vector<T> &_q) : p(_p), q(_q) {}
  void rev(vector<T> &f) const {
    int d = f.size();
    rep(i, d) if (i&1) f[i] = -f[i];
  }
  void even(vector<T> &f) const {
    int d = (f.size() + 1) >> 1;
    rep(i, d) f[i] = f[i<<1];
    f.resize(d);
  }
  void odd(vector<T> &f) const {
    int d = f.size() >> 1;
    rep(i, d) f[i] = f[i<<1|1];
    f.resize(d);
  }
  T operator[] (ll n) const {
    vector<T> _p(p), _q(q), _q_rev(q);
    rev(_q_rev);
    for (; n; n >>= 1) {
      _p = convolution(move(_p), _q_rev);
      if (n&1) odd(_p);
      else     even(_p);
      _q = convolution(move(_q), move(_q_rev));
      even(_q);
      _q_rev = _q; rev(_q_rev);
    }
    return _p[0] / _q[0];
  }
};

} int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  int k;
  cin >> n >> k;
  vector<mint> f(k + 3), g(2 * k + 4);
  f[2] += 1;
  f[k+2] += -1;
  g[0] += 1;
  g[1] += -4;
  g[2] += 5;
  g[3] += -2;
  g[k+1] += 1;
  g[k+2] += -3;
  g[k+3] += 2;
  g[2*k+2] += 1;
  g[2*k+3] += -1;
  auto bm = bostan_mori(f, g);
  auto ans = bm[n] + 1;
  cout << ans.val() << '\n';
}
0