結果
| 問題 |
No.2582 Random Average^K
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-12-10 12:13:44 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 776 ms / 2,000 ms |
| コード長 | 1,143 bytes |
| コンパイル時間 | 846 ms |
| コンパイル使用メモリ | 77,452 KB |
| 最終ジャッジ日時 | 2025-02-18 09:59:10 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll=long long;
using mint=modint998244353;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
const int MAX=11000000;
const ll MOD=998244353;
mint fac[MAX+1],finv[MAX+1],inv[MAX+1];
void set_fac(){
fac[0]=fac[1]=1;
finv[0]=finv[1]=1;
inv[1]=1;
for (int i=2;i<=MAX;i++){
fac[i]=fac[i-1]*i;
inv[i]=-inv[MOD%i]*(MOD/i);
finv[i]=finv[i-1]*inv[i];
}
}
mint cmb(int n,int r){
if (r<0||n<r)return 0;
return fac[n]*finv[r]*finv[n-r];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
set_fac();
int N,K;
cin>>N>>K;
mint ans=0;
for(int i=0;i<N;i++){
if(i%2==0)ans+=cmb(N,i)*mint(N-i).pow(N+K);
else ans-=cmb(N,i)*mint(N-i).pow(N+K);
}
ans*=fac[K]/mint(N).pow(K)/fac[N+K];
cout<<ans.val()<<"\n";
}