結果

問題 No.1856 Mex Sum 2
コンテスト
ユーザー boatmuscles
提出日時 2022-02-26 16:06:08
言語 C++17
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 830 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 513 ms
コンパイル使用メモリ 62,128 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-25 09:23:15
合計ジャッジ時間 2,686 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<cstdio>
#include<algorithm>
#include<atcoder/modint>
using namespace atcoder;
using Mint = modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int N, M;
    scanf("%d %d", &N, &M);
    Mint answer = -(Mint((M+1)<<1).pow(N));
    Mint fact[N+3];
    fact[0] = Mint::raw(1);
    for (int i = 1; i <= N+2; i++) fact[i] = fact[i-1]*Mint::raw(i);
    Mint ifact[N+3];
    ifact[N+2] = fact[N+2].inv();
    for (int i = N+2; (i); i--) ifact[i-1] = ifact[i]*Mint::raw(i);
    for (int i = 0, lim = std::min(M+1, N); i <= lim; i++)
    {
        if(i&1) answer -= Mint((M<<1)-i+1).pow(N)*fact[lim+2]*ifact[i+2]*ifact[lim-i]*Mint::raw(i+1);
        else answer += Mint((M<<1)-i+1).pow(N)*fact[lim+2]*ifact[i+2]*ifact[lim-i]*Mint::raw(i+1);
    }
    printf("%u\n", answer.val());
    return 0;
}
0