結果
問題 | No.1354 Sambo's Treasure |
ユーザー | KoD |
提出日時 | 2021-01-15 17:43:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,308 bytes |
コンパイル時間 | 3,030 ms |
コンパイル使用メモリ | 224,180 KB |
実行使用メモリ | 12,800 KB |
最終ジャッジ日時 | 2024-05-07 01:24:39 |
合計ジャッジ時間 | 7,982 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | WA | - |
testcase_22 | AC | 2 ms
5,376 KB |
testcase_23 | AC | 127 ms
12,672 KB |
testcase_24 | AC | 134 ms
12,800 KB |
testcase_25 | AC | 128 ms
12,672 KB |
testcase_26 | AC | 126 ms
12,672 KB |
testcase_27 | AC | 125 ms
12,604 KB |
testcase_28 | AC | 128 ms
12,800 KB |
testcase_29 | AC | 127 ms
12,604 KB |
testcase_30 | AC | 128 ms
12,800 KB |
testcase_31 | AC | 128 ms
12,672 KB |
testcase_32 | AC | 129 ms
12,672 KB |
testcase_33 | AC | 128 ms
12,672 KB |
testcase_34 | AC | 129 ms
12,672 KB |
testcase_35 | AC | 129 ms
12,672 KB |
testcase_36 | AC | 127 ms
12,800 KB |
testcase_37 | AC | 128 ms
12,672 KB |
testcase_38 | AC | 126 ms
12,672 KB |
testcase_39 | AC | 130 ms
12,672 KB |
testcase_40 | AC | 126 ms
12,672 KB |
testcase_41 | AC | 127 ms
12,672 KB |
testcase_42 | AC | 127 ms
12,672 KB |
testcase_43 | AC | 10 ms
6,400 KB |
testcase_44 | AC | 10 ms
6,400 KB |
testcase_45 | AC | 10 ms
6,528 KB |
testcase_46 | AC | 11 ms
6,528 KB |
testcase_47 | AC | 10 ms
6,400 KB |
testcase_48 | AC | 10 ms
6,400 KB |
testcase_49 | AC | 10 ms
6,528 KB |
testcase_50 | AC | 10 ms
6,400 KB |
testcase_51 | AC | 11 ms
6,400 KB |
testcase_52 | AC | 11 ms
6,528 KB |
testcase_53 | AC | 11 ms
6,400 KB |
testcase_54 | AC | 10 ms
6,400 KB |
testcase_55 | AC | 10 ms
6,400 KB |
testcase_56 | AC | 11 ms
6,400 KB |
testcase_57 | AC | 10 ms
6,528 KB |
testcase_58 | AC | 10 ms
6,400 KB |
testcase_59 | AC | 10 ms
6,400 KB |
testcase_60 | AC | 10 ms
6,528 KB |
testcase_61 | AC | 10 ms
6,400 KB |
testcase_62 | AC | 11 ms
6,400 KB |
testcase_63 | AC | 128 ms
12,672 KB |
コンパイルメッセージ
main.cpp:77: warning: "assert" redefined 77 | #define assert(...) | In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/cassert:44, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:33, from main.cpp:1: /usr/include/assert.h:92: note: this is the location of the previous definition 92 | # define assert(expr) \ |
ソースコード
#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; } }; struct FpUtil { Vec<Fp> fact; Vec<Fp> inv_fact; explicit FpUtil(const unsigned size): fact(size + 1), inv_fact(size + 1) { fact[0] = Fp(1); for (int i = 1; i <= (int) size; ++i) { fact[i] = fact[i - 1] * Fp(i); } inv_fact[size] = fact[size].inv(); for (int i = (int) size; i >= 1; --i) { inv_fact[i - 1] = inv_fact[i] * Fp(i); } } Fp binom(const unsigned a, const unsigned b) const { return fact[a + b] * inv_fact[a] * inv_fact[b]; } }; #define assert(...) int main() { int N, M, L, K; std::cin >> N >> M >> L >> K; assert(1 <= N && N <= 200000); assert(0 <= M && M <= std::min(N - 1, 100000)); assert(0 <= L && L <= std::min((N + 1) * (N + 1), 100)); assert(0 <= K && K <= 100000); Vec<std::pair<int, int>> Pts; Pts.reserve(2 + M); Pts.emplace_back(0, 0); for (int i = 0; i < M; ++i) { int x, y; std::cin >> x >> y; Pts.emplace_back(x, y); } Pts.emplace_back(N, N); for (int i = 0; i + 1 < (int) Pts.size(); ++i) { assert(Pts[i].first < Pts[i + 1].first); assert(Pts[i].second < Pts[i + 1].second); } std::set<std::pair<int, int>> set; for (int i = 0; i < L; ++i) { int x, y; std::cin >> x >> y; assert(0 <= x && x <= N); assert(0 <= y && y <= N); set.emplace(x, y); } assert((int) set.size() == L); Vec<Vec<std::pair<int, int>>> Tig(Pts.size()); for (int i = 0; i + 1 < (int) Pts.size(); ++i) { Tig[i + 1].push_back(Pts[i]); } Vec<bool> inevitable(Pts.size()); for (const auto [x, y]: set) { bool inside = true; for (int i = 0; i < (int) Pts.size(); ++i) { if (x == Pts[i].first && y == Pts[i].second) { inevitable[i] = true; inside = false; break; } } if (!inside) { continue; } for (int i = 1; i < (int) Pts.size(); ++i) { if (Pts[i - 1].first <= x && x <= Pts[i].first && Pts[i - 1].second <= y && y <= Pts[i].second) { Tig[i].emplace_back(x, y); } } } for (int i = 1; i < (int) Pts.size(); ++i) { Tig[i].push_back(Pts[i]); } Vec<Fp> dp(L + 1); dp[inevitable[0]] = Fp(1); FpUtil util(2 * N); for (int i = 1; i < (int) Pts.size(); ++i) { const auto &vec = Tig[i]; const int size = (int) vec.size(); Vec<Vec<Fp>> path(size, Vec<Fp>(size)); for (int j = 0; j < size; ++j) { for (int k = j + 1; k < size; ++k) { if (vec[k].second < vec[j].second) { continue; } path[j][k] = util.binom(vec[k].first - vec[j].first, vec[k].second - vec[j].second); for (int l = j + 1; l < k; ++l) { if (vec[l].second >= vec[j].second && vec[k].second >= vec[l].second) { path[j][k] -= path[j][l] * util.binom(vec[k].first - vec[l].first, vec[k].second - vec[l].second); } } } } Vec<Vec<Fp>> calc(size - 2, Vec<Fp>(L + 1)); for (int j = 0; j < size - 2; ++j) { for (int k = 0; k < L; ++k) { calc[j][k + 1] += dp[k] * path[0][j + 1]; } } for (int j = 0; j < size - 2; ++j) { for (int k = j + 1; k < size - 2; ++k) { for (int l = 0; l < L; ++l) { calc[k][l + 1] = calc[j][l] * path[j + 1][k + 1]; } } } Vec<Fp> next(L + 1); for (int k = 0; k + inevitable[i] <= L; ++k) { next[k + inevitable[i]] += dp[k] * path[0][vec.size() - 1]; for (int j = 0; j < size - 2; ++j) { next[k + inevitable[i]] += calc[j][k] * path[j + 1][vec.size() - 1]; } } dp = std::move(next); } std::cout << std::accumulate(dp.begin(), dp.begin() + std::min(L, K) + 1, Fp(0)).val << '\n'; }