結果
問題 | No.1897 Sum of 2nd Max |
ユーザー |
|
提出日時 | 2022-04-08 22:15:41 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 421 ms / 2,000 ms |
コード長 | 883 bytes |
コンパイル時間 | 3,020 ms |
コンパイル使用メモリ | 245,740 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-28 12:54:01 |
合計ジャッジ時間 | 8,960 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/modint> using namespace std; using Mint = atcoder::modint998244353; struct Mat { Mint A[3][3]; }; Mat mul(Mat a, Mat b) { Mat c; for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 3; k++) c.A[i][j] += a.A[i][k] * b.A[k][j]; return c; } Mat pow(Mat a, int x) { if (x == 1) return a; auto ret = pow(a, x / 2); ret = mul(ret, ret); if (x & 1) ret = mul(ret, a); return ret; } int main() { int N, K; cin >> N >> K; Mint ans = 0; for (int x = 1; x <= K; x++) { Mat A; A.A[0][0] = K; A.A[0][1] = K - (x - 1); A.A[1][1] = x - 1; A.A[1][2] = K - (x - 1); A.A[2][2] = x - 1; A = pow(A, N); ans += A.A[0][2]; } cout << ans.val() << endl; }