結果
問題 | No.1354 Sambo's Treasure |
ユーザー | 👑 jupiro |
提出日時 | 2021-01-19 13:37:24 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 179 ms / 2,000 ms |
コード長 | 4,210 bytes |
コンパイル時間 | 1,859 ms |
コンパイル使用メモリ | 144,004 KB |
実行使用メモリ | 27,392 KB |
最終ジャッジ日時 | 2023-08-22 11:00:37 |
合計ジャッジ時間 | 10,387 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
27,084 KB |
testcase_01 | AC | 37 ms
26,788 KB |
testcase_02 | AC | 37 ms
26,812 KB |
testcase_03 | AC | 40 ms
26,832 KB |
testcase_04 | AC | 39 ms
26,792 KB |
testcase_05 | AC | 32 ms
26,836 KB |
testcase_06 | AC | 33 ms
26,788 KB |
testcase_07 | AC | 33 ms
26,992 KB |
testcase_08 | AC | 34 ms
26,816 KB |
testcase_09 | AC | 34 ms
26,784 KB |
testcase_10 | AC | 35 ms
26,840 KB |
testcase_11 | AC | 37 ms
26,796 KB |
testcase_12 | AC | 38 ms
26,808 KB |
testcase_13 | AC | 39 ms
26,884 KB |
testcase_14 | AC | 37 ms
26,992 KB |
testcase_15 | AC | 37 ms
27,084 KB |
testcase_16 | AC | 37 ms
26,852 KB |
testcase_17 | AC | 38 ms
26,816 KB |
testcase_18 | AC | 35 ms
27,060 KB |
testcase_19 | AC | 33 ms
26,844 KB |
testcase_20 | AC | 37 ms
26,856 KB |
testcase_21 | AC | 34 ms
27,080 KB |
testcase_22 | AC | 34 ms
27,036 KB |
testcase_23 | AC | 168 ms
27,112 KB |
testcase_24 | AC | 179 ms
27,164 KB |
testcase_25 | AC | 166 ms
27,216 KB |
testcase_26 | AC | 169 ms
27,196 KB |
testcase_27 | AC | 169 ms
27,188 KB |
testcase_28 | AC | 165 ms
27,224 KB |
testcase_29 | AC | 177 ms
27,192 KB |
testcase_30 | AC | 167 ms
27,392 KB |
testcase_31 | AC | 165 ms
27,108 KB |
testcase_32 | AC | 163 ms
27,116 KB |
testcase_33 | AC | 164 ms
27,104 KB |
testcase_34 | AC | 171 ms
27,088 KB |
testcase_35 | AC | 168 ms
27,296 KB |
testcase_36 | AC | 172 ms
27,232 KB |
testcase_37 | AC | 171 ms
27,120 KB |
testcase_38 | AC | 165 ms
27,112 KB |
testcase_39 | AC | 168 ms
27,128 KB |
testcase_40 | AC | 175 ms
27,160 KB |
testcase_41 | AC | 169 ms
27,152 KB |
testcase_42 | AC | 162 ms
27,212 KB |
testcase_43 | AC | 38 ms
26,964 KB |
testcase_44 | AC | 40 ms
26,864 KB |
testcase_45 | AC | 43 ms
27,076 KB |
testcase_46 | AC | 42 ms
26,884 KB |
testcase_47 | AC | 40 ms
26,848 KB |
testcase_48 | AC | 45 ms
26,856 KB |
testcase_49 | AC | 43 ms
27,068 KB |
testcase_50 | AC | 43 ms
26,904 KB |
testcase_51 | AC | 47 ms
26,992 KB |
testcase_52 | AC | 43 ms
27,048 KB |
testcase_53 | AC | 47 ms
26,872 KB |
testcase_54 | AC | 45 ms
26,876 KB |
testcase_55 | AC | 44 ms
26,872 KB |
testcase_56 | AC | 45 ms
26,920 KB |
testcase_57 | AC | 42 ms
26,992 KB |
testcase_58 | AC | 41 ms
26,868 KB |
testcase_59 | AC | 42 ms
26,956 KB |
testcase_60 | AC | 44 ms
27,048 KB |
testcase_61 | AC | 42 ms
26,932 KB |
testcase_62 | AC | 45 ms
26,876 KB |
testcase_63 | AC | 168 ms
27,200 KB |
ソースコード
#include <iostream> #include <string> #include <sstream> #include <stack> #include <algorithm> #include <cmath> #include <queue> #include <bitset> #include <iomanip> #include <limits> #include <chrono> #include <random> #include <array> #include <unordered_map> #include <functional> #include <complex> #include <numeric> #include <cctype> #include <map> #include <set> #include <cstdlib> #include <bitset> #include <tuple> #include <assert.h> #include <deque> #include <utility> #include <fstream> using namespace std; typedef long long ll; using ull = unsigned long long; 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; } //template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); }return a; } //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; //constexpr long long mod = 1000000007LL; constexpr long long mod = 998244353; struct mint { long long x; mint(long long x = 0) :x((x% mod + mod) % mod) {} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; const int MAX = (int)1e6; long long fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } mint COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod); } mint LCOM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; if (k > n / 2) k = n - k; mint res = 1; for (int i = 0; i < k; i++) res *= (n - i); res *= finv[k]; return res; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); COMinit(); int n, m, L, K; cin >> n >> m >> L >> K; vector<pair<int, int>> cp(m + 2); for (int i = 1; i <= m; i++) cin >> cp[i].first >> cp[i].second; cp[m + 1] = { n,n }; vector<pair<int, int>> tg(L); for (auto& p : tg) cin >> p.first >> p.second; sort(tg.begin(), tg.end()); int tcur = 0; vector dp1(2, vector<mint>(L + 1)); int cur = 0; int nxt = 1; dp1[0][0] = 1; for (int i = 0; i + 1 < (int)cp.size(); i++) { vector<pair<int, int>> vp; vp.emplace_back(cp[i]); while (tcur < L and tg[tcur] <= cp[i + 1]) vp.emplace_back(tg[tcur++]); vp.emplace_back(cp[i + 1]); int sz = (int)vp.size(); vector dp2(sz, vector<mint>(sz + 1)); dp2[0][0] = 1; for (int j = 1; j < sz; j++) { for (int k = sz; k >= 0; k--) { for (int l = 0; l < j; l++) { int dx = vp[j].first - vp[l].first; int dy = vp[j].second - vp[l].second; if (dx < 0 or dy < 0) continue; if (j + 1 < sz and k > 0) dp2[j][k] += dp2[l][k - 1] * COM(dx + dy, dx); if (j + 1 == sz) dp2[j][k] += dp2[l][k] * COM(dx + dy, dx); } if ((j + 1 < sz and k > 0) or j + 1 == sz) for (int l = k + 1; l <= sz; l++) dp2[j][k] -= dp2[j][l]; } } for (int j = 0; j <= L; j++) dp1[nxt][j] = 0; for (int j = 0; j <= L; j++) { for (int k = 0; k <= sz; k++) { if (j + k <= L) { dp1[nxt][j + k] += dp1[cur][j] * dp2.back()[k]; } } } swap(cur, nxt); } mint res = 0; for (int i = 0; i <= min(L, K); i++) res += dp1[cur][i]; cout << res.x << "\n"; }