結果
問題 | No.2807 Have Another Go (Easy) |
ユーザー |
![]() |
提出日時 | 2024-10-20 23:42:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 3,000 ms |
コード長 | 1,094 bytes |
コンパイル時間 | 2,096 ms |
コンパイル使用メモリ | 198,168 KB |
最終ジャッジ日時 | 2025-02-24 22:05:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 46 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/modint>using namespace std;using ll = long long;using namespace atcoder;using mint=modint998244353;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);int N, M, K, C;cin >> N >> M >> K;/*(Cを通る場合)+(N+Cを通る場合)-(両方通る場合)残りがxマスであるとき、x-1で1~6x-2で2~6.x-6で6を出したらゴール*/vector<mint> dp(N*M);dp[0] = 1;for (int i=0; i<N*M; i++){for (int j=1; j<=6; j++){if (i+j<N*M){dp[i+j] += dp[i];}}}auto f=[&](ll X)->mint{mint res=0;for (int i=1; i<=6; i++){if (X-i>=0) res += dp[X-i]*(7-i);}return res;};while(K--){cin >> C;mint ans=0;ans += dp[C] * f(N*2-C);ans += dp[C+N] * f(N-C);//C進んでからN進むans -= dp[C] * dp[N] * f(N-C);cout << ans.val() << endl;}return 0;}