結果
問題 | No.3096 Snake Path |
ユーザー |
|
提出日時 | 2025-02-23 16:00:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 264 ms / 2,000 ms |
コード長 | 1,876 bytes |
コンパイル時間 | 7,096 ms |
コンパイル使用メモリ | 334,096 KB |
実行使用メモリ | 71,808 KB |
最終ジャッジ日時 | 2025-02-23 16:00:45 |
合計ジャッジ時間 | 11,233 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> #define rep(i, p, n) for (ll i = p; i < (ll)(n); i++) #define rep2(i, p, n) for (ll i = p; i >= (ll)(n); i--) using namespace std; using ll = long long; using ld = long double; const double pi = 3.141592653589793; const long long inf = 2 * 1e9; const long long linf = 4 * 1e18; const ll mod1 = 1000000007; const ll mod2 = 998244353; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } // atcoder #include <atcoder/all> using namespace atcoder; using mint1 = modint1000000007; using mint2 = modint998244353; vector<pair<ll, ll>> base = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}}; int main() { ll N, K; cin >> N >> K; vector<vector<vector<mint2>>> dp(N, vector<vector<mint2>>(K + 1, vector<mint2>(5))); dp[0][0][0] = 1; vector<vector<ll>> li = {{1, 1, 0, 2, 2}, {0, 1, 1, 2, 2}}; vector<vector<ll>> nx = {{1, 1, 1, 1, 0}, {1, 0, 1, 1, 1}, {1, 1, 1, 0, 1}, {0, 0, 1, 1, 0}, {1, 0, 0, 0, 1}}; rep(i, 0, N - 1) { rep(j, 0, K + 1) { rep(k, 0, 5) { rep(l, 0, 5) { if (j + li[i % 2][l] > K) { continue; } dp[i + 1][j + li[i % 2][l]][l] += dp[i][j][k] * nx[k][l]; } } } } mint2 ans = 0; rep(i, 0, K + 1) { rep(j, 0, 5) { if (N % 2 == 0 && j == 3) { continue; } if (N % 2 == 1 && j == 4) { continue; } ans += dp[N - 1][i][j]; } } cout << ans.val() << endl; }