結果
問題 | No.2434 RAKUTAN de RAKUTAN |
ユーザー |
![]() |
提出日時 | 2023-08-18 23:20:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 80 ms / 2,000 ms |
コード長 | 2,141 bytes |
コンパイル時間 | 2,708 ms |
コンパイル使用メモリ | 227,996 KB |
最終ジャッジ日時 | 2025-02-16 10:48:06 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic warning "-Wunused-function"using namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;} int main() {ios::sync_with_stdio(false);cin.tie(0);int n, h, x, g, b;cin >> n >> h >> x;cin >> g;vector<P> d;rep(_, g) {int gi;cin >> gi;d.emplace_back(gi, 1);}cin >> b;rep(_, b) {int bi;cin >> bi;d.emplace_back(bi, -1);}sort(all(d));if (d.empty() || d.back().first != n) {d.emplace_back(n, 0);}VVI dp(x);dp[0].emplace_back(0);int now = 0;constexpr int INF = 1001001001;auto trans = [&](int i, int j, int ni, int nj) {if (nj > dp[ni].size()) {dp[ni].resize(nj + 1, -INF);dp[ni][nj] = dp[i][j];} else if (nj == dp[ni].size()) {dp[ni].emplace_back(dp[i][j]);} else {chmax(dp[ni][nj], dp[i][j]);}};for(auto [i, c] : d) {// [now, i+1-x] -> i+1-xif (now < i + 1 - x) {int l = min((i + 1 - x) - now, x - 1);rep(i, l) {rep(j, dp[i].size()) {trans(i, j, i+1, j);}dp[i].clear();}rotate(dp.begin(), dp.begin() + l, dp.end());now = i + 1 - x;}while(now != i) {dp.emplace_back();rep(j, dp[0].size()) {trans(0, j, 1, j);trans(0, j, x, j + 1);}dp.erase(dp.begin());now++;}rep(j, dp[0].size()) dp[0][j] += c;}int ans = -INF;rrep(j, min<int>(dp[0].size(), h + 1)) chmax(ans, dp[0][j]);cout << ans << '\n';}