結果

問題 No.409 ダイエット
ユーザー btk
提出日時 2016-04-17 21:13:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,244 bytes
コンパイル時間 1,486 ms
コンパイル使用メモリ 162,148 KB
実行使用メモリ 14,976 KB
最終ジャッジ日時 2024-10-04 10:30:07
合計ジャッジ時間 7,428 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55 TLE * 1 -- * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

/*想定TLE解法その1*/

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef __int128 INT;


/*cin高速化*/
struct INIT{INIT(){ios::sync_with_stdio(false);cin.tie(0);}}init;

ostream& operator<<(ostream &os,INT x){
    LL y;
    y=x;
    assert(y==x);
    os << y;
    return os;
}
istream& operator>>(istream &is,INT& x){
    LL y;
    is >> y;
    x = y;
    return is;
}

const INT INF = 1e24;
int main() {
    INT N,A,B,W;
    /*input N,A,B,W*/
    {
        cin >> N >> A >> B >> W;
        assert(1 <= N && N <= 300000);
        assert(0 <= A && A <= 1000000);
        assert(0 <= B && B <= 1000000);
        assert(0 <= W && W <= 1000000);
    }
    vector<INT> D(N);
    {
        for(auto& it : D){
            cin >> it;
            assert(0 <= it && it <= 1000000);
        }
    }
    /*DP*/
    vector<INT> dp(N+1,INF),nxt(N+1);
    dp[0] = W;
    for(int i = 0; i < N; i++){
        nxt[0] = dp[N] + D[i];
        for(int j = 0; j < N; j++){
            nxt[0] = min(nxt[0],dp[j] + D[i]);
            nxt[j+1] = dp[j] - A + (j + 1) * B;
        }
        swap(dp,nxt);
    }

    /*output*/
    INT res = INF;
    for(auto& it : dp)
        res = min(res,it);
    cout << res << endl;
    return 0;
}
0