結果

問題 No.860 買い物
ユーザー stone_725stone_725
提出日時 2019-08-09 21:42:11
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 853 bytes
コンパイル時間 720 ms
コンパイル使用メモリ 94,760 KB
実行使用メモリ 17,840 KB
最終ジャッジ日時 2023-08-20 12:41:28
合計ジャッジ時間 4,315 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,764 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 42 ms
4,624 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;
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;
    long long sum = 0;
    for(int i = id + 1; i <= n; i++){
        minItem = min(minItem, item[i - 1].first);
        if(i - id == 1){
            sum += item[i - 1].first;
        }else{
            sum += item[i - 1].first + item[i - 1].second;
        }
        res = min(res, sum + minItem + dfs(i));
    }
    return dp[id] = res;
}

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