結果

問題 No.860 買い物
ユーザー stone_725stone_725
提出日時 2019-08-09 22:04:02
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 945 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 93,816 KB
実行使用メモリ 18,616 KB
最終ジャッジ日時 2023-08-20 12:42:03
合計ジャッジ時間 3,569 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 41 ms
4,660 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int n;
vector<pair<long long, long long>> item;
vector<long long> sum;
long long dp[100001];

long long dfs(int id){
    if(id == n){
        return 0;
    }
    if(~dp[id]) return dp[id];
    long long res = 1ll << 62, minItem = 1ll << 62;
    for(int i = id + 1; i <= n; i++){
        if(id - i > 1 && item[i - 1].second > item[i - 1].first * 2) break;
        minItem = min(minItem, item[i - 1].first);
        res = min(res, sum[i] - sum[id] - item[id].second + minItem + dfs(i));
    }
    return dp[id] = res;
}

int main(){
    cin >> n;
    item.resize(n);
    sum.resize(n + 1);
    for(auto&& i : item){
        cin >> i.first >> i.second;
    }
    for(int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + item[i - 1].first + item[i - 1].second;
    }
    memset(dp, -1, sizeof dp);
    cout << dfs(0) << "\n";
}
0