結果
| 問題 |
No.2434 RAKUTAN de RAKUTAN
|
| コンテスト | |
| ユーザー |
noya2
|
| 提出日時 | 2023-08-13 02:19:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 1,265 bytes |
| コンパイル時間 | 3,382 ms |
| コンパイル使用メモリ | 267,296 KB |
| 実行使用メモリ | 48,308 KB |
| 最終ジャッジ日時 | 2024-11-20 18:38:59 |
| 合計ジャッジ時間 | 4,754 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
template <typename T, typename U> inline bool chmax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
int main(){
int n, h, x; cin >> n >> h >> x;
h = min(h,1010);
vector<pair<int,int>> mas;
int g; cin >> g;
while (g--){
int y; cin >> y;
mas.emplace_back(y,1);
}
int b; cin >> b;
while (b--){
int y; cin >> y;
mas.emplace_back(y,-1);
}
ranges::sort(mas);
vector<int> a = {0};
int pre = 0;
for (auto [y, p] : mas){
int w = y - pre - 1;
if (w > 6) w = 6;
while (w--) a.emplace_back(0);
a.emplace_back(p);
pre = y;
}
if (pre != n){
int w = n - pre - 1;
if (w > 6) w = 6;
while (w--) a.emplace_back(0);
a.emplace_back(0);
pre = n;
}
n = (int)(a.size()) - 1;
vector<vector<int>> dp(n+1,vector<int>(h+1,-1e9));
dp[0][0] = 0;
for (int i = 0; i < n; i++) for (int j = 0; j <= h; j++) {
chmax(dp[i+1][j],dp[i][j]+a[i+1]);
if (i+x <= n && j+1 <= h){
chmax(dp[i+x][j+1],dp[i][j]+a[i+x]);
}
}
int ans = -1e9;
for (int i = 0; i <= h; i++) chmax(ans,dp[n][i]);
cout << ans << endl;
}
noya2