結果

問題 No.1552 Simple Dice Game
ユーザー 👑 KazunKazun
提出日時 2021-06-19 03:59:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 958 ms / 2,500 ms
コード長 603 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 64,772 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-05 00:40:45
合計ジャッジ時間 12,298 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 807 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 705 ms
4,380 KB
testcase_10 AC 798 ms
4,380 KB
testcase_11 AC 830 ms
4,384 KB
testcase_12 AC 247 ms
4,380 KB
testcase_13 AC 688 ms
4,380 KB
testcase_14 AC 415 ms
4,380 KB
testcase_15 AC 496 ms
4,380 KB
testcase_16 AC 69 ms
4,380 KB
testcase_17 AC 120 ms
4,376 KB
testcase_18 AC 652 ms
4,380 KB
testcase_19 AC 935 ms
4,380 KB
testcase_20 AC 946 ms
4,380 KB
testcase_21 AC 946 ms
4,376 KB
testcase_22 AC 936 ms
4,380 KB
testcase_23 AC 958 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>

using namespace std;
using ll=long long;

ll pow_mod(ll a, ll n, ll mod){
    if (n==0) return 1;
    else if (n&1) return (a*pow_mod(a,n-1,mod)%mod);
    else{
        ll b=pow_mod(a,n/2,mod);
        return b*b%mod;
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    
    ll Mod=998244353;
    ll X=pow_mod(M,N,Mod)*(M+1)%Mod;
    ll Y=0;

    for (int l=1; l<=M; l++) Y+=pow_mod(l,N,Mod);
    
    ll Z=(X-2*Y)%Mod; Z+=Mod; Z%=Mod;

    ll two_inv=pow_mod(2,Mod-2,Mod);
    
    N%=Mod;
    ll k=(N*two_inv)%Mod; k=(k*(M+1))%Mod;

    Z*=k; Z%=Mod;
    cout << Z << endl;
}
0