結果
問題 | No.2434 RAKUTAN de RAKUTAN |
ユーザー |
|
提出日時 | 2023-08-19 14:59:34 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,904 bytes |
コンパイル時間 | 1,920 ms |
コンパイル使用メモリ | 178,124 KB |
実行使用メモリ | 59,904 KB |
最終ジャッジ日時 | 2024-11-29 08:25:36 |
合計ジャッジ時間 | 3,066 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 4 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; template<class T> istream& operator >> (istream& is, vector<T>& vec) { for(T& x : vec) is >> x; return is; } template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { if(vec.empty()) return os; os << vec[0]; for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it; return os; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, h, x, g, b; cin >> n >> h >> x >> g; vector<int> G(g), ca; cin >> G >> b; vector<int> B(b); cin >> B; ca.reserve(2 * x * (g + b)); for(auto &&v : G){ for(int d = -x; d <= x; d++){ int nv = v + d; if(nv < 0 || nv > n) continue; ca.emplace_back(nv); } } for(auto &&v : B){ for(int d = -x; d <= x; d++){ int nv = v + d; if(nv < 0 || nv > n) continue; ca.emplace_back(nv); } } for(int i = 0; i < min(x, n); i++){ ca.emplace_back(i); ca.emplace_back(n - i); } sort(ca.begin(), ca.end()); ca.erase(unique(ca.begin(), ca.end()), ca.end()); int m = ca.size(), i = 0; vector<int> tb(m); for(auto &&v : G){ while(ca[i] < v) i++; tb[i] = 1; } i = 0; for(auto &&v : B){ while(ca[i] < v) i++; tb[i] = -1; } h = min({h, m, b}); vector<vector<int>> dp(m, vector<int>(h + 1, -(1 << 30))); dp[0][h] = 0; for(int i = 0; i + 1 < m; i++){ for(int j = 0; j <= h; j++){ dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + tb[i + 1]); } if(i + x < m){ for(int j = 1; j <= h; j++){ dp[i + x][j - 1] = max(dp[i + x][j - 1], dp[i][j] + tb[i + x]); } } } cout << *max_element(dp.back().begin(), dp.back().end()) << '\n'; }