結果

問題 No.2659 Manga App
ユーザー てんぷらてんぷら
提出日時 2024-03-01 02:18:18
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,922 ms / 6,000 ms
コード長 1,482 bytes
コンパイル時間 5,087 ms
コンパイル使用メモリ 316,856 KB
実行使用メモリ 175,744 KB
最終ジャッジ日時 2024-03-01 20:53:33
合計ジャッジ時間 29,448 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 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 1 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 2 ms
6,676 KB
testcase_14 AC 11 ms
6,676 KB
testcase_15 AC 9 ms
6,676 KB
testcase_16 AC 16 ms
6,676 KB
testcase_17 AC 4 ms
6,676 KB
testcase_18 AC 12 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 5 ms
6,676 KB
testcase_22 AC 6 ms
6,676 KB
testcase_23 AC 23 ms
7,552 KB
testcase_24 AC 3 ms
6,676 KB
testcase_25 AC 16 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 9 ms
6,676 KB
testcase_29 AC 4 ms
6,676 KB
testcase_30 AC 10 ms
6,676 KB
testcase_31 AC 4 ms
6,676 KB
testcase_32 AC 948 ms
175,744 KB
testcase_33 AC 947 ms
175,744 KB
testcase_34 AC 953 ms
38,528 KB
testcase_35 AC 1,020 ms
52,352 KB
testcase_36 AC 2,922 ms
64,512 KB
testcase_37 AC 1,027 ms
52,352 KB
testcase_38 AC 1,019 ms
52,480 KB
testcase_39 AC 1,025 ms
52,480 KB
testcase_40 AC 1,297 ms
55,040 KB
testcase_41 AC 1,621 ms
57,600 KB
testcase_42 AC 1,995 ms
60,160 KB
testcase_43 AC 2,432 ms
62,336 KB
testcase_44 AC 2,916 ms
64,512 KB
testcase_45 AC 2,908 ms
64,512 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>> dp(n);
    dp[0][0] = x;
    ll ans = longinf;
    rep(i, n - 1) {
        for(auto [ct, cx] : dp[i]) {
            int k = i;
            ll nt = ct;
            while(k < n - 1) {
                nt += a[k++];
                if(nt % d > b) {
                    break;
                }
            }
            if(k == n - 1) {
                ll ret = max(nt - cx, 0ll);
                if(ret % d > b) {
                    ret = (ret + d - 1) / d * d;
                }
                ans = min(ans, ret);
            } else {
                ll s = (nt + d - 1) / d * d;
                dp[k][s] = max(dp[k][s], cx);

                ll e = nt / d * d + b;
                ll need = nt - e;
                if(cx >= need) {
                    dp[k][e] = max(dp[k][e], cx - need);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
0