結果

問題 No.3809 Count Bipartite Permutations
コンテスト
ユーザー GhostMFC
提出日時 2026-11-21 01:57:13
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 783 ms / 2,000 ms
+ 254µs
コード長 862 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,825 ms
コンパイル使用メモリ 362,512 KB
実行使用メモリ 660,096 KB
最終ジャッジ日時 2026-11-21 01:57:38
合計ジャッジ時間 15,837 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#define All(x) x.begin(),x.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

using ll=long long;

const int mod=998244353;

signed main(){
    IOS
    int n,k;
    cin>>n>>k;
    int low=(1+n)*n/2,upp=n*n;
    if(k<low||k>upp) return cout<<0<<'\n',0;

    vector<vector<vector<ll>>> dp(2*n+1,vector<vector<ll>>(n+1,vector<ll>(upp+1)));
    dp[0][0][0]=1;
    for(int i=1;i<=2*n;++i){
        for(int j=0;j<=i&&j<=n;++j){
            for(int s=0;s<=upp;++s){
                // i 作为较小的
                if(s>=i&&j) (dp[i][j][s]+=dp[i-1][j-1][s-i])%=mod;
                // i 作为较大的
                if(j<i&&j<n) (dp[i][j][s]+=dp[i-1][j+1][s]*(j+1)%mod)%=mod;
            }
        }
    }

    ll n_=1;
    for(int i=1;i<=n;++i) n_=n_*i%mod;
    cout<<dp[2*n][0][k]*n_%mod<<'\n';
}
0