結果

問題 No.3809 Count Bipartite Permutations
コンテスト
ユーザー tnakao0123
提出日時 2026-11-25 13:38:29
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 137 ms / 2,000 ms
+ 827µs
コード長 1,887 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 58,632 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-25 13:38:34
合計ジャッジ時間 4,159 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/* -*- coding: utf-8 -*-
 *
 * 3809.cc:  No.3809 Count Bipartite Permutations - yukicoder
 */

#include<cstdio>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 80;
const int MAX_K = MAX_N * MAX_N;
const int MOD = 998244353;

/* typedef */

template<const int MOD>
struct MI {
  int v;
  MI(): v() {}
  MI(int _v): v(_v % MOD) { if (v < 0) v += MOD; }
  MI(long long _v): v(_v % MOD) { if (v < 0) v += MOD; }

  explicit operator int() const { return v; }
  
  MI operator+(const MI m) const { return MI(v + m.v); }
  MI operator-(const MI m) const { return MI(v + MOD - m.v); }
  MI operator-() const { return MI(MOD - v); }
  MI operator*(const MI m) const { return MI((long long)v * m.v); }

  MI &operator+=(const MI m) { return (*this = *this + m); }
  MI &operator-=(const MI m) { return (*this = *this - m); }
  MI &operator*=(const MI m) { return (*this = *this * m); }

  bool operator==(const MI m) const { return v == m.v; }
  bool operator!=(const MI m) const { return v != m.v; }

  MI pow(int n) const {  // a^n % MOD
    MI pm = 1, a = *this;
    while (n > 0) {
      if (n & 1) pm *= a;
      a *= a;
      n >>= 1;
    }
    return pm;
  }

  MI inv() const { return pow(MOD - 2); }
  MI operator/(const MI m) const { return *this * m.inv(); }
  MI &operator/=(const MI m) { return (*this = *this / m); }
};

using mi = MI<MOD>;

/* global variables */

mi dp[MAX_N + 1][MAX_K + 1];

/* subroutines */

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  if (k > n * n) { puts("0"); return 0; }

  int n2 = n * 2;
  dp[0][0] = 1;
  
  for (int i = n2; i >= 1; i--)
    for (int c = n - 1; c >= 0; c--)
      for (int s = k - i; s >= 0; s--) {
	int e = n2 - c * 2 - i;
	if (e > 0)
	  dp[c + 1][s + i] += dp[c][s] * e;
      }

  mi p = dp[n][k];
  for (int i = 2; i <= n; i++) p *= i;

  printf("%d\n", (int)p);
  
  return 0;
}
0