結果

問題 No.1552 Simple Dice Game
ユーザー se1ka2se1ka2
提出日時 2021-06-18 22:17:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 313 ms / 2,500 ms
コード長 799 bytes
コンパイル時間 645 ms
コンパイル使用メモリ 64,344 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 23:27:30
合計ジャッジ時間 5,329 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 313 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 237 ms
4,384 KB
testcase_10 AC 278 ms
4,380 KB
testcase_11 AC 281 ms
4,380 KB
testcase_12 AC 83 ms
4,380 KB
testcase_13 AC 235 ms
4,384 KB
testcase_14 AC 137 ms
4,380 KB
testcase_15 AC 172 ms
4,380 KB
testcase_16 AC 25 ms
4,388 KB
testcase_17 AC 41 ms
4,380 KB
testcase_18 AC 218 ms
4,380 KB
testcase_19 AC 310 ms
4,384 KB
testcase_20 AC 310 ms
4,380 KB
testcase_21 AC 306 ms
4,384 KB
testcase_22 AC 308 ms
4,380 KB
testcase_23 AC 310 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

ll modpow(ll x, ll n){
    ll res = 1, r = x;
    while(n){
        if(n & 1) res = res * r % MOD;
        r = r * r % MOD;
        n >>= 1;
    }
    return res;
}

ll foo(ll m, ll n){
    ll s = m * (m + 1) / 2 % MOD;
    return s * modpow(m, n - 1) % MOD * (n % MOD) % MOD;
}

ll foo2(ll m, ll i, ll n){
    ll s = (m * (m + 1) / 2 - i * (i - 1) / 2) % MOD;
    return s * modpow(m - i + 1, n - 1) % MOD * (n % MOD) % MOD;
}

int main()
{
    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    for(ll i = m; i > 0; i--){
        ans = (ans + (foo(i, n) - foo(i - 1, n) + MOD) * i) % MOD;
    }
    for(ll i = 1; i <= m; i++){
        ans = (ans - foo2(m, i, n) + MOD) % MOD;
    }
    cout << ans << endl;
}
0