結果
問題 | No.1897 Sum of 2nd Max |
ユーザー |
👑 ![]() |
提出日時 | 2022-04-08 22:29:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 1,000 bytes |
コンパイル時間 | 726 ms |
コンパイル使用メモリ | 78,116 KB |
最終ジャッジ日時 | 2025-01-28 16:24:23 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#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;