結果

問題 No.2582 Random Average^K
ユーザー otoshigootoshigo
提出日時 2023-12-10 12:13:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 531 ms / 2,000 ms
コード長 1,143 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 79,284 KB
実行使用メモリ 132,424 KB
最終ジャッジ日時 2023-12-10 12:13:58
合計ジャッジ時間 10,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 409 ms
132,424 KB
testcase_01 AC 403 ms
132,424 KB
testcase_02 AC 436 ms
132,424 KB
testcase_03 AC 405 ms
132,424 KB
testcase_04 AC 407 ms
132,424 KB
testcase_05 AC 431 ms
132,424 KB
testcase_06 AC 403 ms
132,424 KB
testcase_07 AC 403 ms
132,424 KB
testcase_08 AC 439 ms
132,424 KB
testcase_09 AC 428 ms
132,424 KB
testcase_10 AC 457 ms
132,424 KB
testcase_11 AC 474 ms
132,424 KB
testcase_12 AC 510 ms
132,424 KB
testcase_13 AC 531 ms
132,424 KB
testcase_14 AC 406 ms
132,424 KB
testcase_15 AC 505 ms
132,424 KB
testcase_16 AC 486 ms
132,424 KB
testcase_17 AC 457 ms
132,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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";
}
0