結果

問題 No.2659 Manga App
ユーザー てんぷらてんぷら
提出日時 2024-03-01 02:08:43
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 698 ms / 6,000 ms
コード長 2,830 bytes
コンパイル時間 5,357 ms
コンパイル使用メモリ 316,416 KB
実行使用メモリ 174,208 KB
最終ジャッジ日時 2024-03-01 20:53:08
合計ジャッジ時間 10,428 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 5 ms
6,676 KB
testcase_13 AC 3 ms
6,676 KB
testcase_14 AC 8 ms
6,676 KB
testcase_15 AC 8 ms
6,676 KB
testcase_16 AC 11 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 10 ms
6,676 KB
testcase_19 AC 3 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 5 ms
6,676 KB
testcase_23 AC 18 ms
7,552 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 11 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 7 ms
6,676 KB
testcase_29 AC 3 ms
6,676 KB
testcase_30 AC 8 ms
6,676 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 695 ms
174,208 KB
testcase_33 AC 698 ms
174,208 KB
testcase_34 AC 148 ms
38,528 KB
testcase_35 AC 203 ms
52,224 KB
testcase_36 AC 265 ms
64,384 KB
testcase_37 AC 203 ms
52,224 KB
testcase_38 AC 204 ms
52,352 KB
testcase_39 AC 206 ms
52,352 KB
testcase_40 AC 224 ms
54,912 KB
testcase_41 AC 228 ms
57,472 KB
testcase_42 AC 238 ms
60,032 KB
testcase_43 AC 251 ms
62,208 KB
testcase_44 AC 263 ms
64,384 KB
testcase_45 AC 259 ms
64,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/all>
#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
using namespace std;
using namespace atcoder;
using mint = modint998244353;
const int inf = 1000000007;
const ll longinf = 1ll << 60;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll b, c, x;
    cin >> b >> c >> x;
    ll d = b + c;
    vector<ll> a(n - 1);
    rep(i, n - 1) cin >> a[i];
    vector<unordered_map<ll, ll>> dps(n), dpe(n);
    dps[0][0] = x;
    ll ans = longinf;
    rep(i, n - 1) {
        {
            int k = i;
            ll t = 0;
            while(k < n - 1) {
                t += a[k++];
                if(t % d > b) {
                    break;
                }
            }
            if(k == n - 1) {
                for(auto [ct, cx] : dps[i]) {
                    ll ret = max(ct + t - cx, 0ll);
                    if(ret % d > b) {
                        ret = (ret + d - 1) / d * d;
                    }
                    ans = min(ans, ret);
                }
            } else {
                ll s = (t + d - 1) / d * d;
                ll e = t / d * d + b;
                ll need = t - e;
                for(auto [ct, cx] : dps[i]) {
                    dps[k][ct + s] = max(dps[k][ct + s], cx);
                }
                for(auto [ct, cx] : dps[i]) {
                    if(cx < need) {
                        continue;
                    }
                    dpe[k][ct + e] = max(dpe[k][ct + e], cx - need);
                }
            }
        }
        {
            int k = i;
            ll t = b;
            while(k < n - 1) {
                t += a[k++];
                if(t % d > b) {
                    break;
                }
            }
            if(k == n - 1) {
                t -= b;
                for(auto [ct, cx] : dpe[i]) {
                    ll ret = max(ct + t - cx, 0ll);
                    if(ret % d > b) {
                        ret = (ret + d - 1) / d * d;
                    }
                    ans = min(ans, ret);
                }
            } else {
                ll s = (t + d - 1) / d * d;
                ll e = t / d * d + b;
                ll need = t - e;
                s -= b;
                e -= b;
                for(auto [ct, cx] : dpe[i]) {
                    dps[k][ct + s] = max(dps[k][ct + s], cx);
                }
                for(auto [ct, cx] : dpe[i]) {
                    if(cx < need) {
                        continue;
                    }
                    dpe[k][ct + e] = max(dpe[k][ct + e], cx - need);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0