結果
問題 |
No.1354 Sambo's Treasure
|
ユーザー |
![]() |
提出日時 | 2021-01-15 18:02:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,806 bytes |
コンパイル時間 | 2,278 ms |
コンパイル使用メモリ | 207,616 KB |
最終ジャッジ日時 | 2025-01-17 18:18:53 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 20 MLE * 41 |
ソースコード
#include <bits/stdc++.h> template <class T> using Vec = std::vector<T>; constexpr unsigned MOD = 998244353; struct Fp { unsigned val; explicit Fp(const unsigned val = 0): val(val) { } void operator += (const Fp other) { val += other.val; if (val >= MOD) { val -= MOD; } } void operator -= (const Fp other) { val += MOD - other.val; if (val >= MOD) { val -= MOD; } } void operator *= (const Fp other) { val = (unsigned long long) val * other.val % MOD; } Fp operator + (const Fp other) const { Fp ret(*this); ret += other; return ret; } Fp operator - (const Fp other) const { Fp ret(*this); ret -= other; return ret; } Fp operator * (const Fp other) const { Fp ret(*this); ret *= other; return ret; } Fp inv() const { Fp ret(1), mult(*this); unsigned exp = MOD - 2; while (exp > 0) { if (exp & 1) { ret *= mult; } exp >>= 1; mult *= mult; } return ret; } }; int main() { int N, M, L, K; std::cin >> N >> M >> L >> K; Vec<Vec<bool>> isOk(N + 1, Vec<bool>(N + 1)); { int lx = 0, ly = 0; for (int i = 0; i < M; ++i) { int x, y; std::cin >> x >> y; for (int s = lx; s <= x; ++s) { for (int t = ly; t <= y; ++t) { isOk[s][t] = true; } } lx = x; ly = y; } for (int s = lx; s <= N; ++s) { for (int t = ly; t <= N; ++t) { isOk[s][t] = true; } } } Vec<Vec<bool>> isTig(N + 1, Vec<bool>(N + 1)); { for (int i = 0; i < L; ++i) { int x, y; std::cin >> x >> y; isTig[x][y] = true; } } Vec<Vec<Vec<Fp>>> dp(N + 1, Vec<Vec<Fp>>(N + 1, Vec<Fp>(K + 1))); dp[0][0][0] = Fp(1); for (int i = 0; i <= N; ++i) { for (int j = 0; j <= N; ++j) { for (int k = 0; k <= K; ++k) { if (i + 1 <= N && isOk[i + 1][j]) { const auto nk = k + isTig[i + 1][j]; if (nk <= K) { dp[i + 1][j][nk] += dp[i][j][k]; } } if (j + 1 <= N && isOk[i][j + 1]) { const auto nk = k + isTig[i][j + 1]; if (nk <= K) { dp[i][j + 1][nk] += dp[i][j][k]; } } } } } Fp ans; for (int i = 0; i <= K; ++i) { ans += dp[N][N][i]; } return 0; }