結果

問題 No.1897 Sum of 2nd Max
ユーザー polylogKpolylogK
提出日時 2021-12-12 21:29:29
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 2,104 ms
コンパイル使用メモリ 199,196 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-18 23:51:33
合計ジャッジ時間 4,582 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 87 ms
4,380 KB
testcase_04 AC 83 ms
4,376 KB
testcase_05 AC 44 ms
4,380 KB
testcase_06 AC 45 ms
4,376 KB
testcase_07 AC 58 ms
4,376 KB
testcase_08 AC 46 ms
4,376 KB
testcase_09 AC 90 ms
4,376 KB
testcase_10 AC 88 ms
4,376 KB
testcase_11 AC 88 ms
4,380 KB
testcase_12 AC 88 ms
4,384 KB
testcase_13 AC 90 ms
4,380 KB
testcase_14 AC 19 ms
4,376 KB
testcase_15 AC 20 ms
4,380 KB
testcase_16 AC 29 ms
4,380 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 26 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 87 ms
4,380 KB
testcase_31 AC 92 ms
4,380 KB
testcase_32 AC 65 ms
4,376 KB
testcase_33 AC 97 ms
4,380 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