結果

問題 No.1897 Sum of 2nd Max
ユーザー polylogKpolylogK
提出日時 2021-12-12 21:29:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 2,173 ms
コンパイル使用メモリ 200,980 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 06:42:26
合計ジャッジ時間 4,360 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 86 ms
5,376 KB
testcase_04 AC 83 ms
5,376 KB
testcase_05 AC 44 ms
5,376 KB
testcase_06 AC 45 ms
5,376 KB
testcase_07 AC 57 ms
5,376 KB
testcase_08 AC 46 ms
5,376 KB
testcase_09 AC 90 ms
5,376 KB
testcase_10 AC 87 ms
5,376 KB
testcase_11 AC 88 ms
5,376 KB
testcase_12 AC 88 ms
5,376 KB
testcase_13 AC 90 ms
5,376 KB
testcase_14 AC 19 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 29 ms
5,376 KB
testcase_17 AC 21 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 87 ms
5,376 KB
testcase_31 AC 90 ms
5,376 KB
testcase_32 AC 65 ms
5,376 KB
testcase_33 AC 96 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using i64 = std::int_fast64_t;

i64 powmod(i64 x, i64 n, int mod = 998244353) {
	i64 ret = 1;
	while(n) {
		if(n & 1) (ret *= x) %= mod;
		(x *= x) %= mod;
		n >>= 1;
	}
	return ret;
}

int main() {
	i64 n, k; scanf("%lld%lld", &n, &k);

	const int MOD = 998244353;

	auto f = [&](i64 x) -> i64 { // ソート後、二番目の要素が x 以下であるような組合せ数
		const i64 A = powmod(k, n);
		const i64 B = n * x % MOD * powmod(k - x, n - 1) % MOD;
		const i64 C = powmod(k - x, n);
		return ((A - B - C) % MOD + MOD) % MOD;
	};

	i64 ans = 0;
	for(int i = 1; i <= k; i++) {
		i64 count = f(i) - f(i - 1);
		count = (count % MOD + MOD) % MOD;
		ans = (ans + count * (k - i + 1) % MOD) % MOD;
	}
	printf("%lld\n", ans);
	return 0;
}
0