結果

問題 No.1897 Sum of 2nd Max
ユーザー 👑 NachiaNachia
提出日時 2022-04-08 22:29:44
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 1,000 bytes
コンパイル時間 889 ms
コンパイル使用メモリ 79,428 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 00:57:51
合計ジャッジ時間 2,810 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 68 ms
4,380 KB
testcase_04 AC 65 ms
4,380 KB
testcase_05 AC 33 ms
4,380 KB
testcase_06 AC 34 ms
4,380 KB
testcase_07 AC 44 ms
4,380 KB
testcase_08 AC 36 ms
4,376 KB
testcase_09 AC 69 ms
4,376 KB
testcase_10 AC 66 ms
4,376 KB
testcase_11 AC 68 ms
4,380 KB
testcase_12 AC 68 ms
4,376 KB
testcase_13 AC 68 ms
4,380 KB
testcase_14 AC 16 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 24 ms
4,376 KB
testcase_17 AC 19 ms
4,376 KB
testcase_18 AC 22 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 68 ms
4,376 KB
testcase_31 AC 68 ms
4,376 KB
testcase_32 AC 48 ms
4,380 KB
testcase_33 AC 70 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)

using m32 = atcoder::modint998244353;

int main(){
    m32 ans = 0;
    int N, K; cin >> N >> K;
    for(int max2=1; max2<=K; max2++){
        m32 tmp = 0;
        tmp += m32(max2-1) * m32(K-max2+1).pow(N-1) * N;
        tmp -= m32(max2-1) * m32(K-max2).pow(N-1) * N;
        ans += tmp * max2;
    }
    for(int max2=1; max2<=K; max2++){
        m32 tmp = 0;
        tmp += m32(K-max2+1).pow(N);
        tmp -= m32(K-max2).pow(N-1) * N;
        tmp -= m32(K-max2).pow(N);
        ans += tmp * max2;
    }
    ans = m32(K).pow(N) * (K+1) - ans;
    cout << ans.val() << '\n';
    return 0;
}

struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0