結果
問題 | No.2434 RAKUTAN de RAKUTAN |
ユーザー |
![]() |
提出日時 | 2023-08-18 22:43:18 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 433 ms / 2,000 ms |
コード長 | 2,601 bytes |
コンパイル時間 | 2,518 ms |
コンパイル使用メモリ | 204,076 KB |
最終ジャッジ日時 | 2025-02-16 10:27:32 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> #ifdef LOCAL #include <debug.hpp> #else #define debug(...) void(0) #endif using namespace std; typedef long long ll; #define all(x) begin(x), end(x) constexpr int INF = (1 << 30) - 1; constexpr long long IINF = (1LL << 60) - 1; constexpr int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1}; template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; } template <class T> ostream& operator<<(ostream& os, const vector<T>& v) { auto sep = ""; for (const auto& x : v) os << exchange(sep, " ") << x; return os; } template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = forward<U>(y), true); } template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = forward<U>(y), true); } template <class T> void mkuni(vector<T>& v) { sort(begin(v), end(v)); v.erase(unique(begin(v), end(v)), end(v)); } template <class T> int lwb(const vector<T>& v, const T& x) { return lower_bound(begin(v), end(v), x) - begin(v); } const int MAX = 10010; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N, H, X; cin >> N >> H >> X; int G; cin >> G; vector<int> g(G); for (int& x : g) cin >> x; int B; cin >> B; vector<int> b(B); for (int& x : b) cin >> x; sort(all(g)); sort(all(b)); vector<int> cand; cand.emplace_back(0); cand.emplace_back(N); for (int& x : g) { for (int i = 0; i <= X; i++) { if (x - i > 0) { cand.emplace_back(x - i); } } } for (int& x : b) { for (int i = 0; i <= X; i++) { if (x - i > 0) { cand.emplace_back(x - i); } } } mkuni(cand); int len = cand.size(); chmin(H, MAX); vector dp(len, vector<int>(H + 1, -INF)); dp[0][0] = 0; for (int i = 0, p = 0, q = 0, k = 0; i < len; i++) { while (p < G and g[p] < cand[i]) p++; while (q < B and b[q] < cand[i]) q++; int add = 0; if (p < G and g[p] == cand[i]) add++; if (q < B and b[q] == cand[i]) add--; int to = cand[i] + X; while (k < len and cand[k] < to) k++; for (int j = 0; j <= H; j++) { int& val = dp[i][j]; if (val == -INF) continue; val += add; if (i + 1 < len) chmax(dp[i + 1][j], val); if (k < len and j + 1 <= H) chmax(dp[k][j + 1], val); } } int ans = *max_element(all(dp.back())); cout << ans << '\n'; return 0; }