結果

問題 No.2575 Almost Increasing Sequence
ユーザー noshi91noshi91
提出日時 2023-12-01 05:34:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,738 ms / 10,000 ms
コード長 2,760 bytes
コンパイル時間 2,595 ms
コンパイル使用メモリ 224,892 KB
実行使用メモリ 6,548 KB
スコア 200,000
最終ジャッジ日時 2023-12-02 23:39:55
合計ジャッジ時間 40,184 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,734 ms
6,548 KB
testcase_01 AC 1,727 ms
6,548 KB
testcase_02 AC 1,734 ms
6,548 KB
testcase_03 AC 1,724 ms
6,548 KB
testcase_04 AC 1,729 ms
6,548 KB
testcase_05 AC 1,726 ms
6,548 KB
testcase_06 AC 1,728 ms
6,548 KB
testcase_07 AC 1,731 ms
6,548 KB
testcase_08 AC 1,733 ms
6,548 KB
testcase_09 AC 1,728 ms
6,548 KB
testcase_10 AC 1,731 ms
6,548 KB
testcase_11 AC 1,730 ms
6,548 KB
testcase_12 AC 1,730 ms
6,548 KB
testcase_13 AC 1,732 ms
6,548 KB
testcase_14 AC 1,738 ms
6,548 KB
testcase_15 AC 1,728 ms
6,548 KB
testcase_16 AC 1,730 ms
6,548 KB
testcase_17 AC 1,733 ms
6,548 KB
testcase_18 AC 1,730 ms
6,548 KB
testcase_19 AC 1,730 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#include <atcoder/modint>
using mint = atcoder::modint998244353;
static constexpr int N = 10000;
using poly = std::array<mint, N + 1>;
using coef = std::array<int, 3>;
using hp = std::map<coef, poly>;

coef add(coef c, int i) {
  c[i]++;
  return c;
}

coef proj(coef c, int i) {
  c[i] = 0;
  return c;
}

int main() {
  int K;
  std::cin >> K;

  std::array<mint, N + 1> fact, ifact;
  fact[0] = 1;
  for (int i = 1; i <= N; i++)
    fact[i] = fact[i - 1] * i;
  ifact[N] = 1 / fact[N];
  for (int i = N; i >= 1; i--)
    ifact[i - 1] = ifact[i] * i;

  std::map<coef, mint> pd;
  pd[{0, 0, 0}] = 1;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 3; j++) {
      // x_i - x_j
      for (int k = 0; k < 2; k++) {
        std::map<coef, mint> nx;
        for (const auto& [c, v] : pd) {
          nx[add(c, i)] += v;
          nx[add(c, j)] -= v;
        }
        pd = std::move(nx);
      }
    }
  }
  for (auto it = pd.begin(); it != pd.end();) {
    if (it->second == mint(0))
      it = pd.erase(it);
    else
      ++it;
  }

  poly ans;
  std::array<hp, 3> dp;
  for (int col = 0; col + 3 <= N; col++) {
    for (int i = 1; i < 3; i++) {
      int st = std::min(col * i, N + 1);
      int w = std::min(i, N + 1 - st);
      for (auto& [c, v] : dp[i]) {
        std::copy_backward(v.begin() + st, v.end() - w, v.end());
        std::fill(v.begin() + st, v.begin() + st + w, mint(0));
      }
    }
    {
      int h = (col + 1) * 3;
      if (h < N + 1) {
        std::array<mint, 7> pow;
        pow[0] = 1;
        for (int i = 1; i < 7; i++)
          pow[i] = pow[i - 1] * (col + 1);
        mint a = ifact[col + 1] * ifact[col + 1];
        std::array<mint, 7> pc;
        for (int j = 0; j < 7; j++)
          pc[j] = a * pow[j];
        for (const auto& [c, v] : pd) {
          dp[2][proj(c, 2)][h] += pc[c[2]] * v;
        }
      }
    }
    poly temp;
    for (int i = 1; i >= 0; i--) {
      int h = (col + 1) * (i + 1);
      if (h >= N + 1)
        continue;
      std::array<mint, 7> pow;
      pow[0] = 1;
      for (int t = 1; t < 7; t++)
        pow[t] = pow[t - 1] * (col + 3 - i);
      mint a = ifact[col + 3 - i] * ifact[col + 3 - i];
      std::array<mint, 7> pc;
      for (int j = 0; j < 7; j++)
        pc[j] = a * pow[j];
      for (const auto& [c, v] : dp[i + 1]) {
        auto& t = i ? dp[i][proj(c, i)] : temp;
        mint aa = pc[c[i]];
        for (int k = h; k < N + 1; k++)
          t[k] += aa * v[k];
      }
    }
    mint a = mint(col + 1).pow(K);
    for (int k = 0; k < N + 1; k++) {
      ans[k] += a * temp[k];
    }
  }

  std::cout << N << "\n";
  for (int i = 1; i <= N; i++) {
    std::cout << (ans[i] * fact[i] * fact[i]).val() << " \n"[i == N];
  }

  return 0;
}
0