結果

問題 No.1100 Boxes
ユーザー KumaTachiRenKumaTachiRen
提出日時 2023-06-02 09:21:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,868 bytes
コンパイル時間 4,630 ms
コンパイル使用メモリ 268,188 KB
実行使用メモリ 7,064 KB
最終ジャッジ日時 2023-08-28 02:18:12
合計ジャッジ時間 7,490 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,504 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 4 ms
4,376 KB
testcase_21 AC 13 ms
4,768 KB
testcase_22 AC 25 ms
6,584 KB
testcase_23 AC 13 ms
4,768 KB
testcase_24 AC 14 ms
4,996 KB
testcase_25 AC 16 ms
5,056 KB
testcase_26 AC 28 ms
6,884 KB
testcase_27 AC 26 ms
6,444 KB
testcase_28 AC 8 ms
4,384 KB
testcase_29 AC 28 ms
6,676 KB
testcase_30 AC 26 ms
6,364 KB
testcase_31 AC 9 ms
4,404 KB
testcase_32 AC 18 ms
5,284 KB
testcase_33 AC 31 ms
7,048 KB
testcase_34 AC 31 ms
7,064 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 22 ms
6,924 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 14 ms
5,168 KB
testcase_39 AC 30 ms
6,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

struct Fast
{
  Fast()
  {
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (a); i--)
#define Yn(b) cout << ((b) ? "Yes" : "No") << "\n";
#define ll long long

template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}

using mint = modint998244353;

template <typename T>
class factorial
{
  public:
    factorial(int max) : n(max)
    {
      f = vector<T>(n + 1);
      finv = vector<T>(n + 1);
      f[0] = 1;
      for (int i = 1; i <= n; i++)
        f[i] = f[i - 1] * i;
      finv[n] = f[n].inv();
      for (int i = n; i > 0; i--)
        finv[i - 1] = finv[i] * i;
    }
    T fact(int k)
    {
      assert(0 <= k && k <= n);
      return f[k];
    }
    T fact_inv(int k)
    {
      assert(0 <= k && k <= n);
      return finv[k];
    }
    T binom(int k, int r)
    {
      assert(0 <= k && k <= n);
      if (r < 0 || r > k)
        return 0;
      return f[k] * finv[r] * finv[k - r];
    }
    T inv(int k)
    {
      assert(0 < k && k <= n);
      return finv[k] * f[k - 1];
    }

  private:
    int n;
    vector<T> f, finv;
};

int main()
{
  int n, k;
  cin >> n >> k;
  factorial<mint> fact(k);
  vector<mint> f(k + 1, 0), g(k + 1, 0);
  rep(i, 0, k + 1) {
    f[i] = i & 1 ? -fact.fact_inv(i) : fact.fact_inv(i);
    g[i] = mint(i).pow(n) * fact.fact_inv(i);
  }
  auto h = convolution(f, g);
  mint ans = 0;
  for (int j = 1; j <= k; j += 2) {
    ans += h[k - j] * fact.fact(k - j) * fact.binom(k, j);
  }
  cout << ans.val() << endl;
}
0