結果

問題 No.3160 Party Game
ユーザー ha_chan
提出日時 2025-05-23 20:06:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 983 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 195,272 KB
実行使用メモリ 27,092 KB
最終ジャッジ日時 2025-05-27 22:00:19
合計ジャッジ時間 19,842 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<VL> VVL;
typedef long long LL;
#define all(a) (a).begin(), (a).end()
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ALL(a)  (a).begin(),(a).end()
#define pb push_back

#include <atcoder/modint>
using mint = atcoder::modint998244353;

mint fac[3000001],gf[3000001];

mint f(int n,int m){
  return fac[n]*gf[m]*gf[n-m];
}

int main() {
  fac[0]=1;gf[0]=1;
  for(int i=1;i<=3000000;i++){fac[i]=fac[i-1]*i; gf[i]=1/fac[i];}
 int n,m;cin>>n>>m;
 if(n==1){
   mint p=2;
   p=1/p; p*=(m-1);
   cout<<p.val()<<endl;
   return 0;
 }
 mint ans=0;
 mint mae=0;
 for(int a=m-1;a>0;a--){
   if(LL(m)>=LL(a)*n){
     mint mmm=f(m-a*n+n,n);
     ans+=(mmm-mae)*a;
     mae=mmm;
   }
 }
 //cout<<mae.val()<<endl;
 mae=f(m+n,n)-n;
 //cout<<mae.val()<<endl;
 ans/=mae;
 cout<<ans.val()<<endl;
}
0