結果

問題 No.409 ダイエット
ユーザー kimiyukikimiyuki
提出日時 2016-10-20 02:00:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 541 ms / 2,000 ms
コード長 1,046 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 72,136 KB
実行使用メモリ 8,948 KB
最終ジャッジ日時 2023-09-08 17:13:05
合計ジャッジ時間 16,845 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 5 ms
4,376 KB
testcase_36 AC 6 ms
4,376 KB
testcase_37 AC 6 ms
4,376 KB
testcase_38 AC 6 ms
4,380 KB
testcase_39 AC 6 ms
4,376 KB
testcase_40 AC 6 ms
4,376 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 6 ms
4,376 KB
testcase_44 AC 5 ms
4,376 KB
testcase_45 AC 6 ms
4,376 KB
testcase_46 AC 6 ms
4,376 KB
testcase_47 AC 6 ms
4,376 KB
testcase_48 AC 6 ms
4,376 KB
testcase_49 AC 6 ms
4,376 KB
testcase_50 AC 6 ms
4,376 KB
testcase_51 AC 7 ms
4,376 KB
testcase_52 AC 6 ms
4,376 KB
testcase_53 AC 6 ms
4,376 KB
testcase_54 AC 6 ms
4,380 KB
testcase_55 AC 252 ms
5,708 KB
testcase_56 AC 47 ms
4,380 KB
testcase_57 AC 513 ms
8,948 KB
testcase_58 AC 217 ms
5,600 KB
testcase_59 AC 315 ms
6,592 KB
testcase_60 AC 195 ms
5,412 KB
testcase_61 AC 447 ms
8,160 KB
testcase_62 AC 486 ms
8,544 KB
testcase_63 AC 448 ms
7,860 KB
testcase_64 AC 238 ms
5,688 KB
testcase_65 AC 478 ms
8,180 KB
testcase_66 AC 506 ms
8,444 KB
testcase_67 AC 387 ms
7,060 KB
testcase_68 AC 309 ms
6,420 KB
testcase_69 AC 439 ms
7,928 KB
testcase_70 AC 447 ms
7,460 KB
testcase_71 AC 247 ms
5,680 KB
testcase_72 AC 541 ms
8,500 KB
testcase_73 AC 494 ms
8,156 KB
testcase_74 AC 308 ms
6,416 KB
testcase_75 AC 498 ms
8,088 KB
testcase_76 AC 360 ms
6,888 KB
testcase_77 AC 239 ms
5,512 KB
testcase_78 AC 275 ms
5,736 KB
testcase_79 AC 219 ms
5,436 KB
testcase_80 AC 507 ms
8,412 KB
testcase_81 AC 494 ms
8,148 KB
testcase_82 AC 366 ms
6,776 KB
testcase_83 AC 394 ms
7,100 KB
testcase_84 AC 320 ms
6,572 KB
testcase_85 AC 36 ms
4,380 KB
testcase_86 AC 314 ms
6,076 KB
testcase_87 AC 446 ms
7,520 KB
testcase_88 AC 178 ms
4,796 KB
testcase_89 AC 370 ms
6,772 KB
testcase_90 AC 169 ms
4,932 KB
testcase_91 AC 397 ms
7,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
#define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i))
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
const ll inf = ll(1e18)+9;
int main() {
    // input
    int n, a, b, w; cin >> n >> a >> b >> w;
    vector<int> d(n); repeat (i,n) cin >> d[i];
    if (b == 0) {
        // output
        cout << w - a*(ll)n << endl;
    } else {
        // dp
        n += 1;
        d.push_back(0);
        vector<ll> dp(n+1);
        vector<ll> min_dp(n+1);
        dp[0] = w;
        min_dp[0] = w;
        repeat (i,n) {
            ll acc = inf;
            repeat_reverse (j,i+1) {
                setmin(acc, dp[j] - a *(ll) ll(i-j) + b *(ll) (i-j)*(i-j+1)/2);
                if (i-j > 1000) break;
            }
            dp[i+1] = acc + d[i];
            min_dp[i+1] = min(min_dp[i], dp[i+1]);
        }
        // output
        cout << dp[n] << endl;
    }
    return 0;
}
0