結果

問題 No.3160 Party Game
ユーザー askr58
提出日時 2025-05-23 19:45:46
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 702 bytes
コンパイル時間 9,470 ms
コンパイル使用メモリ 332,020 KB
実行使用メモリ 18,888 KB
最終ジャッジ日時 2025-05-27 21:59:06
合計ジャッジ時間 16,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
int main()
{
    ll n,m;
    cin>>n>>m;
    mint ans=0;
    int sz=2000000;
    vector<mint> fact(sz+1,1),invfact(sz+1,1);
    for(int i=0;i<sz;i++){
        fact[i+1]=fact[i]*(i+1);
        invfact[i+1]=fact[i+1].inv();
    }
    auto binom=[&](int x,int y)->mint{
        return fact[x]*invfact[y]*invfact[x-y];
    };
    mint nn=binom(m+n,m)-n;
    assert(nn.val()!=0);
    nn=nn.inv();
    for(ll i=1;i<m;i++){
        if(i*n>m)break;
        ans+=binom(m-i*n+n,n);
        if(n==1)ans--;
    }
    
    ans*=nn;
    cout<<ans.val()<<endl;
    return 0;
}
0