結果

問題 No.1552 Simple Dice Game
ユーザー rtyurtyu
提出日時 2021-07-13 13:47:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,872 ms / 2,500 ms
コード長 1,038 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 71,164 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 09:12:57
合計ジャッジ時間 23,215 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1,872 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1,401 ms
4,376 KB
testcase_10 AC 1,641 ms
4,380 KB
testcase_11 AC 1,649 ms
4,380 KB
testcase_12 AC 481 ms
4,380 KB
testcase_13 AC 1,385 ms
4,376 KB
testcase_14 AC 799 ms
4,380 KB
testcase_15 AC 1,005 ms
4,380 KB
testcase_16 AC 141 ms
4,380 KB
testcase_17 AC 234 ms
4,376 KB
testcase_18 AC 1,299 ms
4,380 KB
testcase_19 AC 1,825 ms
4,380 KB
testcase_20 AC 1,835 ms
4,376 KB
testcase_21 AC 1,817 ms
4,380 KB
testcase_22 AC 1,824 ms
4,380 KB
testcase_23 AC 1,843 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

long long md = 998244353, r2;

long long fp(long long n, long long k)
{
	long long s = 1;
	while (k) {
		if (k & 1) s = (s * n) % md;
		n = (n * n) % md; k /= 2;
	}
	return s;
}

long long sp(long long a, long long d, long long n)
{
	long long t = (a * 2 + d * (n - 1)) % md;
	return (((t * r2) % md) * n) % md;
}

int main()
{ 
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, m; cin >> n >> m;
	long long ans = 0;
	r2 = fp(2, md - 2);
	if (m == 1 || n == 1) {
		cout << 0 << '\n';
		return 0;
	}
	for (long long i = 1; i < m; i++) {
		long long s = 0;
		long long p0 = (fp(i + 1LL, n - 1LL) - fp(i, n - 1LL) * 2 + fp(i - 1LL, n - 1LL) + md * 2) % md;
		long long p1 = (fp(i + 1LL, n - 1LL) - fp(i, n - 1LL) + md) % md;
		s = (p0 * sp((i * (i + 1LL) / 2 - 1LL) % md, i - 1LL, m - i)) % md;
		s = (s + p1 * sp(i + 2LL, 2LL, m - i)) % md;
		s = (s * i) % md;
		ans = (ans + s) % md;
	}
	ans = (ans * (n % md)) % md;
	cout << ans << '\n';
	return 0;
}
0