結果
問題 | No.1354 Sambo's Treasure |
ユーザー | QCFium |
提出日時 | 2021-01-17 15:48:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 5,570 bytes |
コンパイル時間 | 2,464 ms |
コンパイル使用メモリ | 188,344 KB |
実行使用メモリ | 6,528 KB |
最終ジャッジ日時 | 2024-12-16 03:58:51 |
合計ジャッジ時間 | 6,751 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 2 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | AC | 2 ms
5,248 KB |
testcase_23 | AC | 86 ms
5,248 KB |
testcase_24 | AC | 90 ms
5,248 KB |
testcase_25 | AC | 87 ms
5,248 KB |
testcase_26 | AC | 86 ms
5,248 KB |
testcase_27 | AC | 87 ms
5,248 KB |
testcase_28 | AC | 85 ms
5,248 KB |
testcase_29 | AC | 88 ms
5,248 KB |
testcase_30 | AC | 86 ms
5,248 KB |
testcase_31 | AC | 85 ms
5,248 KB |
testcase_32 | AC | 87 ms
5,248 KB |
testcase_33 | AC | 87 ms
5,248 KB |
testcase_34 | AC | 88 ms
5,248 KB |
testcase_35 | AC | 87 ms
5,248 KB |
testcase_36 | AC | 87 ms
5,248 KB |
testcase_37 | AC | 86 ms
5,248 KB |
testcase_38 | AC | 84 ms
5,248 KB |
testcase_39 | AC | 87 ms
5,248 KB |
testcase_40 | AC | 87 ms
5,248 KB |
testcase_41 | AC | 86 ms
5,248 KB |
testcase_42 | AC | 87 ms
5,248 KB |
testcase_43 | AC | 10 ms
6,400 KB |
testcase_44 | AC | 10 ms
6,528 KB |
testcase_45 | AC | 9 ms
6,400 KB |
testcase_46 | AC | 9 ms
6,400 KB |
testcase_47 | AC | 10 ms
6,528 KB |
testcase_48 | AC | 10 ms
6,528 KB |
testcase_49 | AC | 9 ms
6,272 KB |
testcase_50 | AC | 10 ms
6,400 KB |
testcase_51 | AC | 10 ms
6,400 KB |
testcase_52 | AC | 10 ms
6,400 KB |
testcase_53 | AC | 10 ms
6,272 KB |
testcase_54 | AC | 10 ms
6,400 KB |
testcase_55 | AC | 9 ms
6,528 KB |
testcase_56 | AC | 10 ms
6,400 KB |
testcase_57 | AC | 9 ms
6,400 KB |
testcase_58 | AC | 10 ms
6,528 KB |
testcase_59 | AC | 10 ms
6,400 KB |
testcase_60 | AC | 10 ms
6,400 KB |
testcase_61 | AC | 10 ms
6,400 KB |
testcase_62 | AC | 10 ms
6,272 KB |
testcase_63 | AC | 86 ms
5,248 KB |
ソースコード
#include <bits/stdc++.h> int ri() { int n; scanf("%d", &n); return n; } template<int mod> struct ModInt{ int x; ModInt () : x(0) {} ModInt (int64_t x) : x(x >= 0 ? x % mod : (mod - -x % mod) % mod) {} ModInt &operator += (const ModInt &p){ if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator -= (const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator *= (const ModInt &p) { x = (int64_t) x * p.x % mod; return *this; } ModInt &operator /= (const ModInt &p) { *this *= p.inverse(); return *this; } ModInt &operator ^= (int64_t p) { ModInt res = 1; for (; p; p >>= 1) { if (p & 1) res *= *this; *this *= *this; } return *this = res; } ModInt operator - () const { return ModInt(-x); } ModInt operator + (const ModInt &p) const { return ModInt(*this) += p; } ModInt operator - (const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator * (const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator / (const ModInt &p) const { return ModInt(*this) /= p; } ModInt operator ^ (int64_t p) const { return ModInt(*this) ^= p; } bool operator == (const ModInt &p) const { return x == p.x; } bool operator != (const ModInt &p) const { return x != p.x; } explicit operator int() const { return x; } ModInt &operator = (const int p) { x = p; return *this;} ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); } return ModInt(u); } friend std::ostream & operator << (std::ostream &stream, const ModInt<mod> &p) { return stream << p.x; } friend std::istream & operator >> (std::istream &stream, ModInt<mod> &a) { int64_t x; stream >> x; a = ModInt<mod>(x); return stream; } }; typedef ModInt<998244353> mint; template<int mod> struct MComb { using mint = ModInt<mod>; std::vector<mint> fact; std::vector<mint> inv; MComb (int n) { // O(n + log(mod)) fact = std::vector<mint>(n + 1, 1); for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * mint(i); inv.resize(n + 1); inv[n] = fact[n] ^ (mod - 2); for (int i = n; i--; ) inv[i] = inv[i + 1] * mint(i + 1); } mint ncr(int n, int r) { return fact[n] * inv[r] * inv[n - r]; } mint npr(int n, int r) { return fact[n] * inv[n - r]; } mint nhr(int n, int r) { assert(n + r - 1 < (int) fact.size()); return ncr(n + r - 1, r); } }; std::vector<mint> solve(std::vector<std::pair<int, int> > pts, int h, int w) { /* bool map[h + 1][w + 1]; memset(map, 0, sizeof(map)); for (auto i : pts) map[i.first][i.second] = true; std::vector<mint> dp[h + 1][w + 1]; dp[0][0] = { 1 }; for (int i = 0; i <= h; i++) for (int j = 0; j <= w; j++) { if (map[i][j]) dp[i][j].insert(dp[i][j].begin(), 0); if (i < h) { while (dp[i + 1][j].size() < dp[i][j].size()) dp[i + 1][j].push_back(0); for (int k = 0; k < (int) dp[i][j].size(); k++) dp[i + 1][j][k] += dp[i][j][k]; } if (j < w) { while (dp[i][j + 1].size() < dp[i][j].size()) dp[i][j + 1].push_back(0); for (int k = 0; k < (int) dp[i][j].size(); k++) dp[i][j + 1][k] += dp[i][j][k]; } } return dp[h][w]; */ //* pts.insert(pts.begin(), {0, 0}); pts.push_back({h, w}); int n = pts.size(); MComb<998244353> com(h + w); std::vector<mint> dp[n]; dp[0] = { 1 }; for (int i = 0; i < n; i++) { mint tmp = 0; for (int j = dp[i].size(); --j; ) { dp[i][j] -= tmp; tmp += dp[i][j]; } for (int j = i + 1; j < n; j++) { if (pts[j].second < pts[i].second) continue; mint times = com.ncr(pts[j].first - pts[i].first + pts[j].second - pts[i].second, pts[j].first - pts[i].first); while (dp[j].size() <= dp[i].size()) dp[j].push_back(0); for (int k = 0; k < (int) dp[i].size(); k++) dp[j][k + 1] += dp[i][k] * times; } } auto res = dp[n - 1]; res.erase(res.begin()); return res;//*/ } int main() { int n = ri(); int m = ri(); int l = ri(); int k = ri(); std::vector<std::pair<int, int> > check_pts(m); for (auto &i : check_pts) i.first = ri(), i.second = ri(); check_pts.insert(check_pts.begin(), std::pair<int, int>(0, 0)); check_pts.push_back({n, n}); std::vector<std::pair<int, int> > tigers(l); for (auto &i : tigers) i.first = ri(), i.second = ri(); std::sort(tigers.begin(), tigers.end()); { std::vector<std::pair<int, int> > tmp; for (int i = 0; i < l; i++) { int x = tigers[i].first; int y = tigers[i].second; auto itr = std::lower_bound(check_pts.begin(), check_pts.end(), std::pair<int, int>{x, y}); if (y < std::prev(itr)->second || y > itr->second) continue; tmp.push_back(tigers[i]); } tigers = tmp; l = tigers.size(); } int head = 0; std::vector<mint> dp{1}; for (int i = 1; i < (int) check_pts.size(); i++) { int old_head = head; while (head < l && tigers[head] <= check_pts[i]) head++; std::vector<std::pair<int, int> > pts; for (int j = old_head; j < head; j++) pts.push_back({tigers[j].first - check_pts[i - 1].first, tigers[j].second - check_pts[i - 1].second}); auto tmp = solve(pts, check_pts[i].first - check_pts[i - 1].first, check_pts[i].second - check_pts[i - 1].second); std::vector<mint> next(dp.size() + tmp.size() - 1); for (int i = 0; i < (int) dp.size(); i++) for (int j = 0; j < (int) tmp.size(); j++) next[i + j] += dp[i] * tmp[j]; dp = next; } /* for (auto i: dp) std::cerr << i << " "; std::cerr << std::endl;*/ mint res = 0; for (int i = 0; i < (int) dp.size() && i <= k; i++) res += dp[i]; std::cout << res << std::endl; return 0; }