結果

問題 No.2434 RAKUTAN de RAKUTAN
ユーザー noya2noya2
提出日時 2023-08-13 02:19:39
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,265 bytes
コンパイル時間 3,817 ms
コンパイル使用メモリ 265,604 KB
実行使用メモリ 48,456 KB
最終ジャッジ日時 2024-04-30 20:48:27
合計ジャッジ時間 4,718 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 6 ms
6,940 KB
testcase_04 AC 6 ms
6,940 KB
testcase_05 AC 6 ms
6,944 KB
testcase_06 AC 6 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 62 ms
48,024 KB
testcase_11 AC 62 ms
48,256 KB
testcase_12 AC 62 ms
48,384 KB
testcase_13 AC 62 ms
48,456 KB
testcase_14 AC 63 ms
48,256 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 6 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 7 ms
6,944 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 4 ms
6,944 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0