結果

問題 No.1962 Not Divide
ユーザー KudeKude
提出日時 2022-05-28 04:58:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 2,522 bytes
コンパイル時間 2,842 ms
コンパイル使用メモリ 243,156 KB
実行使用メモリ 6,612 KB
最終ジャッジ日時 2023-10-20 22:40:10
合計ジャッジ時間 5,314 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 62 ms
4,916 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 50 ms
4,408 KB
testcase_06 AC 131 ms
6,284 KB
testcase_07 AC 3 ms
4,348 KB
testcase_08 AC 117 ms
5,700 KB
testcase_09 AC 49 ms
4,372 KB
testcase_10 AC 5 ms
4,348 KB
testcase_11 AC 62 ms
4,764 KB
testcase_12 AC 21 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 71 ms
5,244 KB
testcase_15 AC 10 ms
4,348 KB
testcase_16 AC 5 ms
4,348 KB
testcase_17 AC 76 ms
5,436 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 139 ms
6,612 KB
testcase_21 AC 134 ms
6,420 KB
testcase_22 AC 138 ms
6,612 KB
testcase_23 AC 138 ms
6,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic pop
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://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);
  int n, m;
  cin >> n >> m;
  vector<vector<mint>> f(m), g(m);
  for(int k = 1; k <= m; k++) {
    f[k-1].resize(k + 1);
    // x - x^k
    f[k-1][1] += 1;
    f[k-1][k] += -1;
    // 1-2x^k+x^(k+1)
    g[k-1].resize(k + 2);
    g[k-1][0] += 1;
    g[k-1][k] += -2;
    g[k-1][k+1] += 1;
  }
  vector<vector<mint>> g_sf(m + 1), g_sb(m + 1);
  g_sf[0] = {1}, g_sb[m] = {1};
  rep(k, m) g_sf[k + 1] = convolution(g_sf[k], g[k]);
  rrep(k, m) g_sb[k] = convolution(g_sb[k + 1], g[k]);
  vector<mint>& p = g_sf[m];
  vector<mint> q = g_sf[m];
  rep(k, m) {
    auto t = convolution(convolution(g_sf[k], f[k]), g_sb[k + 1]);
    int sz = t.size();
    if ((int)q.size() < sz) q.resize(sz);
    rep(i, sz) q[i] -= t[i];
  }
  bostan_mori<mint> bm(p, q);
  cout << bm[n].val() << '\n';
}
0