結果
問題 | No.2529 Treasure Hunter |
ユーザー |
|
提出日時 | 2023-11-04 01:29:11 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 25 ms / 2,000 ms |
コード長 | 794 bytes |
コンパイル時間 | 3,844 ms |
コンパイル使用メモリ | 254,312 KB |
最終ジャッジ日時 | 2025-02-17 19:03:43 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;using mint = atcoder::modint998244353;int main(){ios::sync_with_stdio(false);cin.tie(0);int T;cin >> T;mint div = mint(1) / 2;while(T--){long long n, m;cin >> n >> m;vector dp(m, vector<mint>(3));dp[0][0] = 1;dp[0][1] = n;if(n >= 4) dp[0][2] = n * (n - 3) / 2;for(int i = 0; i + 1 < m; i++){for(int j = 0; j < 3; j++){dp[i + 1][0] += dp[i][j];dp[i + 1][1] += (n - j) * dp[i][j];if(n >= 4) dp[i + 1][2] += ((n - j) * (n - j - 1) / 2 - (n - 2 * j)) * dp[i][j];}}cout << (dp[m - 1][0] + dp[m - 1][1] + dp[m - 1][2]).val() << '\n';}}